How to obtain an instance's name at runtime?

Dinu C. Gherman gherman at
Wed Jun 23 10:11:30 EDT 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.__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__

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



PS: Do not use my Deja email-address.

Sent via
Share what you know. Learn what you don't.

More information about the Python-list mailing list