By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

name of 'name'

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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.