Q: Name of a arbitary variable as a string?

Erik Max Francis max at alcyone.com
Tue Nov 12 16:33:14 EST 2002


username wrote:

> I am searching for a function (call it: var_name) that do something
> like
> this:
> 
> >>> V="Hello World"
> >>> var_name(V)
> 'V'
> 
> I know how to get it from the locals() Dict. but this is not well
> defined if I have a second variabe
> 
> >>> T="Hello World"

Ah, but that just underscores the point that there can't be any such
function.  Objects are unique; names aren't.  You can have multiple
names bound to the same object, so there is no "right" name for an
object, there is just _a_ name for an object.  There could be others.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If a thing is worth doing, then it is worth doing badly.
\__/ G.K. Chesterton
    ZOE / http://www.alcyone.com/pyos/zoe/
 A simple Python OpenGL rendering engine.



More information about the Python-list mailing list