"What is the name of the function/method that called me?"
Andrew Dalke
dalke at bioreason.com
Fri Oct 15 16:13:31 EDT 1999
Adrian Eyre" <a.eyre at optichrome.com> said:
> def who_called_me():
> try:
> raise "Hack"
> except:
> return sys.exc_info()[2].tb_frame.f_back.f_back.f_code.co_name
May I suggest using
def who_called_me():
try:
raise "Hack"
except "Hack":
return sys.exc_info()[2].tb_frame.f_back.f_back.f_code.co_name
?
There is a slight chance that someone might hit ^C in between
the try/except. Since ^C gets turned into an exception, your
code will effectively ignore it, which isn't the right behaviour.
Andrew Dalke
dalke at acm.org
More information about the Python-list
mailing list