"Jason Doege" <[EMAIL PROTECTED]> wrote

> 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
> behavior.

>>>> 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'

You need to do it thusly:

def newfunc(self, data):
    print 'post change'
MyClass.mfunc = newfunc

That seems to work.
I'm slightly surprised since I didn't know if it would, but it seems 
to!

Alan G 


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to