How to obtain an instance's name at runtime?
rozzin at geekspace.com
Wed Jun 23 21:04:36 EDT 1999
"Dinu C. Gherman" wrote:
> Question: How to obtain an instance's name at runtime?
An *instance's* name? Instances have names?
> >>> c.__name__
Are you actually looking to have the instance tell you what the variable is?
Wouldn't that be both pointless and meaningless, because you already
know what the variable is, otherwise you can't use it, and the variable-name
isn't necessarily the least bit unique, with regard to the variable to which it
Classes have names, and I don't beleive that instances do, because, well...,
the name of the class tells what the class is (as far as `what kind of object
it is'--I don't really know how to expand on that, except with an analogy like
`what species an animal is'), and it usually goes without saying that `what
kind of object it is', with regard to C(), is C().__class__ (or
C().__class__.__name__, if you want a label rather than an object).
More information about the Python-list