Adding methods to instances

Dody Suria Wijaya dodysw at gmail.com
Fri Dec 16 11:40:29 EST 2005


To avoid that:
- subclass Test first

class SubclassTest(T):
     pass

- assign the method to SubclassTest's attribute,

SubclassTest.dynamic = dynamic

- then assign the new class to magic variable __class__ :

t.__class__ = SubclassTest

t.dynamic()

Antoon Pardon wrote:
> But this will make the function a method to all instances of the class.
> Is that what you want? From your first post I had the impression you
> only wanted the function to be the method of one particular instance.
> 



More information about the Python-list mailing list