470,613 Members | 2,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

name of 'name'

Is there a built-in name for the function that returns an object's name? That
is, for

" lambda x: [y for y in globals().keys() if globals()[y]==x][0] " ?

Muchas gracias.

Peace
Jul 18 '05 #1
2 1424
Not exactly sure I understand the question, but here
goes:

If you are talking about a class, you can get the
classname from :

self.__class__.__name__

Hope info helps.

-Larry

"Elaine Jackson" <el***************@home.com> wrote in message
news:W5G7c.878632$ts4.740941@pd7tw3no...
Is there a built-in name for the function that returns an object's name? That is, for

" lambda x: [y for y in globals().keys() if globals()[y]==x][0] " ?

Muchas gracias.

Peace

Jul 18 '05 #2
"Elaine Jackson" <el***************@home.com> wrote in message
news:W5G7c.878632$ts4.740941@pd7tw3no...
Is there a built-in name for the function that returns an object's name? That is, for

" lambda x: [y for y in globals().keys() if globals()[y]==x][0] " ?

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
fashion.

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.

John Roth
Peace

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by stewart.midwinter | last post: by
2 posts views Thread by Ravi | last post: by
21 posts views Thread by TheKeith | last post: by
12 posts views Thread by CJ | last post: by
11 posts views Thread by Andrew Thompson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.