is it possible to add a property to an instance?

Darren Dale dd55 at cornell.edu
Tue Jul 22 09:12:28 EDT 2008


GHUM wrote:

>> Does anyone know if it is possible to add a property to an instance at
>> runtime? I didn't see anything about it in the standard library's new
>> module, google hasn't turned up much either.
> 
> yes. You need nothing special, just add it:
> 
> class fish(object):
>     pass
> 
> a=fish()
> a.legs=4
> print a.legs

Sorry, that's an attribute, not a property.




More information about the Python-list mailing list