Finding the name of a function while defining it
Tim Roberts
timr at probo.com
Wed Dec 26 23:52:15 EST 2012
More information about the Python-list mailing list
Wed Dec 26 23:52:15 EST 2012
- Previous message (by thread): Finding the name of a function while defining it
- Next message (by thread): Finding the name of a function while defining it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Abhas Bhattacharya <abhasbhattacharya2 at gmail.com> wrote: > >While I am defining a function, how can I access the name (separately as >string as well as object) of the function without explicitly naming >it(hard-coding the name)? >For eg. I am writing like: >def abc(): > #how do i access the function abc here without hard-coding the name? Why? Of what value would that be? Note that I'm not merely being obstructionist here. What you're asking here is not something that a Python programmer would normally ask. The compiled code in a function, for example, exists as an object without a name. That unnamed object can be bound to one or more function names, but the code doesn't know that. Example: def one(): print( "Here's one" ) two = one That creates one function object, bound to two names. What name would you expect to grab inside the function? Even more obscure: two = lamba : "one" one = two Which one of these is the "name" of the function? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.
- Previous message (by thread): Finding the name of a function while defining it
- Next message (by thread): Finding the name of a function while defining it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list