how to add property "dynamically"?
Christian Heimes
lists at cheimes.de
Sat Aug 16 19:09:05 EDT 2008
akonsu wrote:
> i am not an expert in python, would someone please tell me what i am
> doing wrong?
You can't add properties to an instance. They must be specified on the
type (aka new style class). Descriptors and magic methods are only
looked up on classes for various reasons - mostly performance reasons.
Old style classes behave differently but properties don't work with old
style classes.
You can archive the same behavior by hooking into __getattr__,
__setattr__ and __delattr__. Mind the speed penelty, though!
Christian
More information about the Python-list
mailing list