How can I get the name of an object???

Gordon McMillan gmcm at hypernet.com
Wed Apr 26 15:48:25 EDT 2000


Jerome Chan wrote:

> object.__name__ returns a tuple of all vars referencings the
> object?

Not at all. Not all objects have an attribute "__name__", and 
Python does not attempt to point back to referencing objects. 
Those objects having a __name__ attribute (eg, class objects, 
function objects) tend to use it for the name given when the 
object was defined.

class A:
  pass

Now A.__name__ is "A".

B = A
And so is B.__name__.


- Gordon




More information about the Python-list mailing list