Find function name in function

Terry Reedy tjreedy at udel.edu
Tue May 20 11:17:52 EDT 2003


"Ilariu Raducan" <lale at fotonation.com> wrote in message
news:5Cqya.14237$pK2.19896 at news.indigo.ie...
> Is it possible to find the function name in that specific function?

In CPython, it is possible to get a handle on a function from within a
function and from that gets its *definition* name (the one in the def
statement), but you are asking about the names bound to the function
..

> I the following example I want to be able to find what name the user
> used to call the function: XXX, yy, zz
> Is that possible?

I do not believe this is sanely possible.  (Insanely would be getting
the code and line number of the calling context, decompiling the code
and using the linenum to find the call and from that the calling name,
if there is one.

> def XXX():
>      #find function name XXX or yy
>      pass
> XXX()
> yy=XXX
> yy()
> zz=XXX
> zz()

You left out the possibility of calling a function without a name or
without it even having any bound names left.

def f(): print 'hi'

fl = [f]
del f
fl[0]()
# prints
hi

Terry J. Reedy






More information about the Python-list mailing list