Puzzle: anonymous tuple unpacking w/o eval

Dirk Gerrits dirk at gerrits.homeip.net
Fri May 16 10:14:43 EDT 2003


Edward K. Ream wrote:
> P.S. Your answer also answers another question I've had for a long time.  If
> f is a function object, we can use inspect to get any kind of info about f.
> But how to get the function object for a function f within f itself?  Now
> it's clear:
> 
>    globals().get("f")
> 
> or anonymously:
> 
>    globals().get(sys._getframe(0).f_code.co_name)
> 
> Many thanks for unlocking this door.

Actually, its much simpler than that. You can just access it like any 
other variable:

 >>> def f():
	return f

 >>> f()
<function f at 0x00A19570>
 >>> f
<function f at 0x00A19570>

Regards,

Dirk Gerrits







More information about the Python-list mailing list