Finding the name of a function while defining it

Jussi Piitulainen jpiitula at ling.helsinki.fi
Sat Dec 29 05:18:05 EST 2012


Abhas Bhattacharya writes:

[...]

> If i call one() and two() respectively, i would like to see "one"
> and "two". I dont have much knowledge of lambda functions, neither
> am i going to use them, so that's something I cant answer.

It's not about lambda. The following does not contain lambda. What
should be name(one)? name(two)? name(foo)? name(fun(1))? name(fun(3))?

def foo():
    return 3

def fun(x):
    def foo(): return x
    return foo

one = fun(1)
two = one

Note that fun(1)() is a valid call where fun(1) is not given any name
outside fun.



More information about the Python-list mailing list