Hello all:

        Until now we see if you have a class like this following in Python

                class MyClass:
                __myPrivateMember = 0

                def __myPrivateMethod(self):
                        # Here goes with what you want freely
                        pass

  mc = MyClass()
  mc._MyClass__myPrivateMethod()

        Here we can still play with "__myPrivateMethod " by giving the
auto-generated prefix (this has been a public secret, you know), so it’s
also for the "__myPrivateMember ".
        What I wanna say is, this isn't a good idea, because since it's
private, why could we still access it? We must abandon anyone to access it
anyway.
        
        Maybe we should generate some random string (such as address of
method/property?) or something like it? This means everytime when we run the
code, the "private" thing is random after compiling, only the Python system
itself know how to access it.
        For those who directly access the "private" things, compiler SHOULD
give them an error, and when running , "AttributeNotFound" still occurs.
        That's all my idea for good practice of programming in OOP for
Python.

-----
This email is signed by the free S/MIME certificate of “CerSign”
(https://www.cersign.com/smime-email-certificates.html)

Be sure to import the root certificate of “CerSign Identity RSA Root” into
your trust root certificate list for encryption, download it from
https://www.cersign.com/root/rsa.html

If you see “smime.p7s” in my letter, you can ignore it because your
mailbox doesn’t support S/MIME

-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to