Monkey patching new style classes

Terry Reedy tjreedy at udel.edu
Thu Nov 29 18:41:30 EST 2007


"David Coffin" <dcoffin at gmail.com> wrote in message 
news:95d1d5660711290359s40274b40tb84415cc006c0001 at mail.gmail.com...
| Is it possible to add an attribute to a new style class where the name of
| that attribute is determined at runtime?

>>> class C(object): pass

>>> setattr(C,'a',1)
>>> C.a
1

And hasattr, getattr work also. 






More information about the Python-list mailing list