As u all know, when we're starting to define a private member or a function in 
Python, led by "__", some like this following:

class MyClass:

    __privateMember = your initValue Here

    def __myPrivateMethod(self):
        # do what u want here...

Now you can still access the private member or private method through the 
"_MyClass__myPrivateMethod()" or "_myClass__privateMember".

What I wanna say here is: 

1. This WON'T give those who begin to learn Python a good understanding of 
"private method/private member" for OOP,.
2. Since it's private, why could we still access them? It will sometimes gives 
a programmer a bad / lazy way of assignment to the private things.

Maybe for the new coming version (or next new release version of Python?), for 
those starting with "__", the compiler will compile them as a random name so 
that we definitely cannot find them at all, so you can NEVER access them 
directly.

Take the "MyClass" as an example: during the backend compiling or generated 
code, it will be something like:

_MyClass_AddressOfYourPrivateMethod/member's ID_YourRealName() 

(Maybe the generated backend code really is: 
"MyClass_0x23ef4ea__myPrivateMethod")

Notice: I'm NOT sure whether the "AddressOfYourPrivateMethod/Member" can be 
only got when running, but what I mean is, this is a random thing which cannot 
be predicted or calculated according to a certain rule. Maybe you can use other 
ways to implement it :)
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to