[Tutor] __ name mangling

Poor Yorick gp@pooryorick.com
Sat Jan 11 20:21:02 2003


I thought that in the following code, __var would be mangled, but it 
wasn't.  Why not?

 >>> class myclass:
    def __init__(self):
        self.__var1 = 'hello'

       
 >>> instance = myclass()
 >>> dir(instance)
['__doc__', '__init__', '__module__', '_myclass__var1']
 >>> instance.__var2 = 'hi'
 >>> dir(instance)
['__doc__', '__init__', '__module__', '__var2', '_myclass__var1']
 >>>

Poor Yorick
gp@pooryorick.com