|| at Feb 18, 2008 at 11:36 am
Fabrizio Pollastri wrote:
Data descriptors are set as attributes of object types. So if one has many
instances of the same class and wants each instance to have a different
property (data descriptor) that can be accessed with a unique attribute
name, it seems to me that there is no solution with data descriptors.
There is any workaround to this? Thank in advance for any help.
You can invent a naming convention and then invoke the getter/setter
... def __getattr__(self, name):
... if not name.startswith("_prop_"):
... return getattr(self, "_prop_" + name).__get__(self)
... raise AttributeError(name)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __getattr__
File "<stdin>", line 5, in __getattr__
a._prop_p = property(lambda self: self.x * self.x)
a.x = 42
But what are you really trying to do?