name of 'name'
newsgroups at jhrothjr.com
Tue Mar 23 00:14:55 CET 2004
"Elaine Jackson" <elainejackson7355 at home.com> wrote in message
news:W5G7c.878632$ts4.740941 at pd7tw3no...
> Is there a built-in name for the function that returns an object's name?
> is, for
> " lambda x: [y for y in globals().keys() if globals()[y]==x] " ?
> Muchas gracias.
I'm not entirely sure what you're asking for, but if it's
an "official" way of finding out what the module level
names(s) that an object is bound to are, then the answer
is: no, there isn't one. Python does not, in general,
maintain any information that would let you get from
an object to the identifiers it's bound to in any simple
There are, of course, a couple of special cases.
Function and class objects both have a __name__
attribute that will tell you what they were bound
to when they were defined. Whether they stayed
there is another question, of course.
More information about the Python-list