Function reference -> name?

Emile van Sebille emile at fenx.com
Fri Nov 14 15:38:08 CET 2003


"Rene Pijlman" <reply.in.the.newsgroup at my.address.is.invalid> wrote in
message news:2lo9rvsob1ejjju20ut308temf0p8l0gbo at 4ax.com...
> When I have a reference to a function (as in parameter 'function' of
f1
> below), how can I get the name of that function ('f2' in the example
> below)?
>
> def f1(function):
>     pass
>     # How to get 'f2' from function?
>
> def f2():
>     pass
>
> f1(f2)
>

>>> def f1():pass
...
>>> f1.func_name
'f1'
>>>>>> dir (f1)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__ge
tattribute__', '__hash__', '__init__', '__module__', '__name__',
'__new__', '__r
educe__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'func_closure',
 'func_code', 'func_defaults', 'func_dict', 'func_doc',
'func_globals', 'func_na
me']




HTH,

--

Emile van Sebille
emile at fenx.com






More information about the Python-list mailing list