Entry
What is the name of the function/method that called me?
Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 231, Adrian Eyre
"""
Packages: miscellaneous.introspection
"""
"""
> Given Python's run-time typing and the ability to generate call stacks
> of line numbers and module names, I suspect there is a way to answer
> this question, but it has escaped my perusal of my books and the online
> documentation. Help appreciated.
"""
import sys
def foo():
bar()
def bar():
print "I was called by " + who_called_me()
def who_called_me():
try:
raise "Hack"
except:
return sys.exc_info()[2].tb_frame.f_back.f_back.f_code.co_name
if __name__ == '__main__':
foo()