Consider this scenario:
import functools
def wrapmethod(f):
@functools.wraps(f)
def wrap(*args, **kwargs):
print '>> %s' % (f.func_name)
r = f(*args, **kwargs)
return r
return wrap
@wrapmethod
def foo():
pass
class Test(object):
@wrapmethod
def foo(self):
pass
test = Test()
test.foo()
foo()
It will output this, as you can see, done at http://codepad.org/Y4xXyjJO :
>> foo
>> foo
I want to learn how to print Test.fooin the first line, indicating the class with which the method is associated.
Any ideas? Is it ever possible?
Thanks in advance.
source
share