[BEGINNER] meta-functions

Michael Hudson mwh at python.net
Sun Dec 23 20:40:07 CET 2001


Igor Mozetic <igor.mozetic at uni-mb.si> writes:

> A simple question from a newbie, sorry.
> 
> I have functions defined normally, def fname(arg1,arg2):
> and also represented as tuples (fname, arg1, arg2),
> to use them by apply(fname, (arg1,arg2)) - no problem.
> 
> How do I make a comparison:  fname == 'string' ?
> I found that I could use repr(fname) and parse the
> resulting string, but I consider this ugly.
> Is there a standard function to return a function name
> as a string?

Try fname.__name__ or fname.func_name, but also try this:

def f():
    pass
g = f
print g.func_name

> I'm restricted to Python 1.5.2.
> I'm not on the list, please reply to me.

Oops.

Cheers,
M.



More information about the Python-list mailing list