Python has a "really hidden encapsulation"?

Aahz aahz at pythoncraft.com
Thu Nov 18 23:04:28 EST 2010


In article <87fwvw214g.fsf at gmail.com>,
Arnaud Delobelle  <arnodel at gmail.com> wrote:
>
>Are you referring to the fact that in Python, if an attribute is a
>property, the __dict__ lookup on the instance is not performed?  As in:
>
>>>> class A:
>...     @property
>...     def x(self): return 42
>... 
>>>> a = A()
>>>> a.__dict__['x'] = 24
>>>> a.x
>42
>>>> a.__dict__['x']
>24
>
>This is documented, but I actually don't know the reason for it.

Because otherwise you would be able to overwrite the property with a
value.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet



More information about the Python-list mailing list