* Carroll, Barry <[EMAIL PROTECTED]> [061212 23:54]:
>    Greetings:
> 
> 
> 
>    Is it possible, from inside a stand-alone function (not a member of a
>    class), to access the string representation of the function's name?  If
>    so, how?
Probably, but it's dirty like help (sys._getframe would be your ticket
into this), but you ask on the tutor mailing list, so you'll probably
don't want this:

def func(x):
     return 2 * x
 
gunc = func
del func

print gunc(10)

The best you can hope to derive is "func" here, but as you can see,
functions are only objects that can be assigned freely.

(Spoiler: it's sys._getframe(0).f_code.co_name, but it will always
only know the name the function was defined under. No way to know how
it was named when it was called. So it's not worth much.)

Andreas
>
> 
> 
>    Regards,
> 
> 
> 
>    Barry
> 
>    [EMAIL PROTECTED]
> 
>    541-302-1107
> 
>    ________________________
> 
>    We who cut mere stones must always be envisioning cathedrals.
> 
>    --Quarry worker's creed
> 
> 
> 
> References
> 
>    Visible links
>    1. mailto:[EMAIL PROTECTED]

> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to