What then is the point of the double underscore (if any) ?:
To prevent masking/shadowing of inherited attributes...
... def __init__(self):
... self.__WhoMe = "From A"
... print "A : ", dir(self)
... super(A, self).__init__()
...... def __init__(self):
... self.__WhoMe = 42
... print "B : ", dir(self)
... super(B, self).__init__()
...... def __init__(self):
... self.__WhoMe = "I'm confuzzled"
... print "Confusion: ", dir(self)
... super(Confusion, self).__init__()
...Confusion: ['_Confusion__WhoMe', '__class__', '__delattr__',
'__dict__', '__doc__', '__getattribute__', '__hash__', '__init__',
'__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', '__weakref__']
A : ['_A__WhoMe', '_Confusion__WhoMe', '__class__', '__delattr__',
'__dict__', '__doc__', '__getattribute__', '__hash__', '__init__',
'__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', '__weakref__']
B : ['_A__WhoMe', '_B__WhoMe', '_Confusion__WhoMe', '__class__',
'__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', '__weakref__']
Note that A, B, and Confusion each have "__WhoMe". Also notice how
each __init__ invokes the parent module __init__; each one adds its
__WhoMe to the object without masking those defined in others.
Without the __, you'd have only ONE attribute after all of that; as
shown next...
... def __init__(self):
... self._WhoMe = "From A"
... print "A : ", dir(self)
... super(A, self).__init__()
...... def __init__(self):
... self._WhoMe = 42
... print "B : ", dir(self)
... super(B, self).__init__()
...... def __init__(self):
... self._WhoMe = "I'm confuzzled"
... print "Confusion: ", dir(self)
... super(Confusion, self).__init__()
...Confusion: ['_WhoMe', '__class__', '__delattr__', '__dict__',
'__doc__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__str__', '__weakref__']
A : ['_WhoMe', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']
B : ['_WhoMe', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']
--
============================================================== <
(e-mail address removed) | Wulfraed Dennis Lee Bieber KD6MOG <
(e-mail address removed) | Bestiaria Support Staff <
============================================================== <
Home Page: <
http://www.dm.net/~wulfraed/> <
Overflow Page: <
http://wlfraed.home.netcom.com/> <