how to add property "dynamically"?

Christian Heimes lists at
Sun Aug 17 01:09:05 CEST 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!


More information about the Python-list mailing list