Thanks to John Clement's answer, I was able to create a function that returns an ordered list of all callers:
def f1(): names = [] frame = inspect.currentframe()
and when called in the chain:
def f2(): return f1() def f3(): return f2() def f4(): return f3() print f4()
looks like that:
['f2', 'f3', 'f4', '<module>']
In my case, I filter out something in '<module>' and after, and then take the last element as the name of the caller.
Or, change the source loop to pledge the first time any name starting with '<' appears:
frame = frame.f_back name = frame.f_code.co_name if name[0] == '<': break names.append(name)
Zachary young
source share