I know how to get the (unique) address of a function, for example:
def func1():
return 1
class A:
def func2():
return 2
def func3(self):
return 3
print('func1:', hex(id(func1)))
print('func2:', hex(id(A.func2)))
print('func3:', hex(id(A.func3)))
But inside any given function, how can I get the address of the caller function, regardless of whether each one of them (the caller and the callee) is a global function, a class function or member function?
I've tried following several answers on similar questions (here for example), most of which seem to suggest using the inspect
module.
But they all seem to be asking about the caller function's name rather than its (unique) address, which is what I am really interested in.
Thank you for helping out.