Matias Surdi <[EMAIL PROTECTED]> wrote: > 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.__dict__['a'] = new.instancemethod(replace_method(a.a),a,A) > > a.a() > > #Result should be: > # Original modified > You are unlikely to get that unless you make 'a' return a result. I get: >>> a.a() Original Traceback (most recent call last): File "<pyshell#16>", line 1, in <module> a.a() File "<pyshell#5>", line 4, in b return other(result) File "<pyshell#3>", line 2, in other return cad + " modified" TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' -- http://mail.python.org/mailman/listinfo/python-list