Get function callers' information in python
I want to get information about the callers of a specific function in python. For example: class SomeClass(): def __init__(self, x): self.x = x def caller(self): return special_func(self.x) def special_func(x): print "My caller is the 'caller' function in an 'SomeClass' class." Is it possible with python? Yes, the sys._getframe() function let's you retrieve frames from the current execution stack, which you can then inspect with the methods and documentation found in the inspect module ; you'll be looking for specific locals in the f_locals attribute, as well as for the f_code information: