How to obtain an instance's name at runtime?

Greg Ewing greg.ewing at compaq.com
Sun Jun 27 17:45:54 EDT 1999


"Dinu C. Gherman" wrote:
> 
> Have a look at the following page, spot the question mark
> and you'll know what I mean:

I've looked at the page, and it helps, but still
doesn't provide enough information to tell exactly
what you want the "name" of the object to be.

The best solution by far would be to give the
object a name explicitly when you create it.
Is this possible, or do you want to retrofit
it onto existing code?

It looks like you want it to be something like
"the name of the first variable to be assigned
a reference to the object". Does this apply to
local variables as well as globals? Instance
variables of another object? What if the object
is never assigned to a variable? What if it
is, but somewhere far removed from where it
is created?

Greg




More information about the Python-list mailing list