How to obtain an instance's name at runtime?

Dinu C. Gherman gherman at my-deja.com
Wed Jun 23 16:11:30 CEST 1999


This is a nasty question, perhaps, so I appologize in
advance if its stupidity level is far above the accepted
average in this newsgroup...

I would like to do the following:

>>> class C:
...    pass
...
>>>
>>> c = C()
>>> C.__class__.__name__ # ok
'C'
>>> c.__name__           # not ok
Traceback (innermost last):
  File "<interactive input>", line 0, in ?
AttributeError: __name__
>>>

Question: How to obtain an instance's name at runtime?
That is I'd like to see this happen (one was or the other):

>>> c.__name__
'c'

I've checked the reference manual, but it's silent about
this topic or I'm too blind...

Fearing-there's-no-such-solution'ly,

Dinu

PS: Do not use my Deja email-address.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list