How to obtain an instance's name at runtime?

Joshua Rosen rozzin at geekspace.com
Thu Jun 24 20:23:51 CEST 1999


Terry Reedy wrote:
> 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
> g=f
> del f
> 
> Now the function which internally thinks of itself as 'f' is referred to
> externally as 'g' and only as 'g'.

	Yes, it makes sense for functions, classes, and modules to all have names,
because they are all -definers-, which is what I think I was trying to say.
	Instances aren't `definers'--they don't act as the root of the definition for
`what something is'.

		-Rozzin.





More information about the Python-list mailing list