Finding the name of a function while defining it

Chris Angelico rosuav at
Thu Dec 27 08:52:45 CET 2012

On Thu, Dec 27, 2012 at 6:46 PM, Abhas Bhattacharya
<abhasbhattacharya2 at> wrote:
> [ a whole lot of double-spaced quoted text - please trim it ]
> If i call one() and two() respectively, i would like to see "one" and "two".

That completely goes against your idea of knowing at compile-time,
because the name "two" isn't anywhere around at that time.

There's no way to know what name was used to look something up. It
might not even have a name - the called function could well have been
returned from another function:

def indirection():
  return lambda: print

import foo
foo.indirection()()("Hello, world!")

What are the names of all the functions called here?


More information about the Python-list mailing list