I\'m writing a decorator, and for various annoying reasons[0] it would be expedient to check if the function it is wrapping is being defined stand-alone or as part of a class (a
Some hacky solution that I've got:
import inspect def my_decorator(f): args = inspect.getargspec(f).args defined_in_class = bool(args and args[0] == 'self') print "%r: %s" %(f, defined_in_class)
But it relays on the presence of self argument in function.
self