__set__ method is not called for class attribute access
__peter__ at web.de
Fri Aug 5 15:00:37 CEST 2011
Duncan Booth wrote:
> The descriptor protocol only works when a value is being accessed or set
> on an instance and there is no instance attribute of that name so the
> value is fetched from the underlying class.
Unlike normal class attributes a descriptor is not shaded by an instance
>>> class A(object):
... def set_x(self, value): self.__dict__["x"] = value/2.0
... def get_x(self): return self.__dict__["x"] * 2.0
... x = property(get_x, set_x)
>>> a = A()
>>> a.x = 42
>>> A.x = "something completely different"
More information about the Python-list