For my logging purpose i want to log all the names of functions where my code is going
Does not matter who is calling the function , i want the the function name in which i declare this line
import inspect
def whoami():
return inspect.stack()[1][3]
def foo():
print(whoami())
currently it prints foo
, i want to print whoami
You probably want inspect.getframeinfo(frame).function
:
import inspect
def whoami():
frame = inspect.currentframe()
return inspect.getframeinfo(frame).function
def foo():
print(whoami())
foo()
prints
whoami