private class members and hasattr
Dragos Chirila
d.chirila at bucarest.finsiel.ro
Fri Jan 23 03:30:46 EST 2004
Hi
I have the following class:
class PropTest:
def __init__(self):
self.prop1 = 1
self._prop2 = 2
self.__prop3 = 3
def testprops(self):
print 'has prop1 %s' % hasattr(self, 'prop1')
print 'has _prop2 %s' % hasattr(self, '_prop2')
print 'has __prop3 %s' % hasattr(self, '__prop3')
and the following test lines:
a = PropTest()
a.testprops()
The output of this is:
has prop1 1
has _prop2 1
has __prop3 0
Why hasattr method doesn't return 1(true) for private member '__prop3' ??
I tested it with Python 2.2.1 and 2.1.3 .
Thanks
Dragos
More information about the Python-list
mailing list