[Tutor] Dynamically changing a class

Jason Doege jdoege at da-test.com
Tue Sep 4 00:15:52 CEST 2007

Hi All,

I'd like to change the behavior of a class' member function dynamically
such that, once changed, all objects of the type would see the new

For instance:

>>> class MyClass (object) :
      def mfunc(self, data):
        print 'pre change behavior'

>>> aMyClassObj = MyClass()
>>> aMyClassObj.mfunc(data)
pre change behavior
>>> def MyClass.mfunc(self, data):  #this does not work :-(
      print 'post change behavior'

>>> aMyClassObj.mfunc(data)
post change behavior

Does anyone have any guidance on how to accomplish this? I'd also like
to be able to add and delete attributes, similarly.

Best regards,
Jason Doege

More information about the Tutor mailing list