Created
May 25, 2012 10:15
-
-
Save alvesjnr/2787137 to your computer and use it in GitHub Desktop.
I didn't get it yet!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(object): | |
__a = 10 | |
a = A() | |
print dir(a) | |
""" | |
should return something like: | |
['_A__a', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] | |
Realize that your variable _a is renamed to _A__a | |
""" | |
class B(object): | |
def __init__(self): | |
self.__b = 10 | |
b = B() | |
print dir(b) | |
""" | |
Again, our variable __b is renamed to _B__b | |
['_B__b', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] | |
""" | |
class C(object): | |
def __init__(self): | |
setattr(self, '__c', 10) | |
c = C() | |
print dir(c) | |
""" | |
But in this case, __c is __c instead of _C__c: | |
['__c', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment