"What is the name of the function/method that called me?"

Jim Althoff jima at aspectdv.com
Fri Oct 15 18:51:54 EDT 1999


Just out of curiosity,

My understanding is that exceptions
are compared by reference and not
by value (is this correct?).

So does

>>>try:
>>>  raise: "Hack"
>>>except "Hack"

only work by happenstance because the standard 
Python implementation keeps a reusable list
of literals (guessing) or because there is something
formal in the language that says it must work?

Thanks,

Jim



At 02:13 PM 10/15/99 -0600, Andrew Dalke wrote:

. . .
>
>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
>
>-- 
>http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list