How to obtain an instance's name at runtime?

Terry Reedy tjreedy at
Thu Jun 24 01:39:25 EDT 1999

In article <37718424.C70BB9DE at>,  says...
>"Dinu C. Gherman" wrote:
>> Question: How to obtain an instance's name at runtime?

rozzin at responded:
>        An *instance's* name? Instances have names?

and others similarly.

As near as I can remember, only three types of objects have definition 
names (in readonly? __name__ attributes): modules, functions, and 
classes.  All others are anonymous, though they may or may not have one 
or more namespace references.

While named objects usually get a namespace (reference) name equal to 
the definition name, there is no necessary connection.  Consider:

def f(): pass
del f

Now the function which internally thinks of itself as 'f' is referred to 
externally as 'g' and only as 'g'.

Terry J. Reedy

More information about the Python-list mailing list