is it possible to add a property to an instance?
GHUM
haraldarminmassa at gmail.com
Tue Jul 22 08:56:06 EDT 2008
> 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
(or print (a.legs) on Python 3.0 and above)
so you add a property to an instance and proove that Darwin was right
in one go.
Harald
More information about the Python-list
mailing list