I have the following code:

--------------------------
import new

class A:
     def a(self):
         print "Original"

def other(cad):
     return cad + " modified"

def replace_method(method):
     def b(self,*args,**kwargs):
         result = method(*args,**kwargs)
         return other(result)
     return b


a = A()

setattr(a,"a",new.instancemethod(replace_method(a.a) ,a,A))

a.a()

#Result should be:
# Original modified

------------------------------

As you can see, what I'm trying to do is "replace" a method with another 
one wich is the same method but with a function applied to it (in this 
case, a string concatenation ( +" modified"))

Can anybody help me with this?




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to