import sys def entryExit(f): def new_f(self,*args): print "Entering", f.__name__,self.__class__.__name__ f(self,*args) print "Exited", f.__name__,self.__class__.__name__ return new_f class A: @entryExit def move(self,g,h): print "hello" print g,h a=A() a.move(5,7) The above code outputs
Entering move A hello 5 7 Exited move A I was able to retrieve the method name as well as the class in which it is define using decorators. But i wasnt able to retrieve the name of the method parameters during runtime.
Basically i need an output like this
Entering move A g,h hello 5 7 Exited move A g,h So what should i add in the print statements to get an output like above.
Thank you
g, hgandhselfis redundant and actually makes your decorator less flexible in this case. Just have(*args, **kwargs)on the wrapper; the implicitselfwill be unpacked correctly when needed for instance methods, but you don't force all methods that the decorator is used on to have at least one argument any more.functoolsmaybe?) which would transform the call signature of the function...