Proper syntax for adding methods to a class instance dynamically?

Fernando Pérez fperez528 at yahoo.com
Mon Apr 22 20:38:32 EDT 2002


I'd like to know what the proper way to do this is. I've been using the new 
module with new.instancemethod(), but the docstring for new isn't very 
confidence inducing:

Docstring:
    Functions to create new objects used by the interpreter.

    You need to know a great deal about the interpreter to use this!


Is there a simpler, perhaps 'safer' way to achieve the same result? What I 
want is to have code which runs after an instance of a certain class has been 
created and which can add new methods to the class instance. I'd also like to 
know how to add them to the whole class. I have some solutions in store but I 
feel they're kind of kludgy.

Thanks for any help,

f.



More information about the Python-list mailing list