How to obtain an instance's name at runtime?

Joshua Rosen 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__
> 'c'

	Are you actually looking to have the instance tell you what the variable is?
Wouldn't that be both [0]pointless and [1]meaningless, because [1]you already
know what the variable is, otherwise you can't use it, and [2]the variable-name
isn't necessarily the least bit unique, with regard to the variable to which it
referrs?
	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).


		-Rozzin.





More information about the Python-list mailing list