Q: Name of a arbitary variable as a string?

Martin v. Loewis martin at v.loewis.de
Tue Nov 12 15:41:48 EST 2002


username <username at ilt.fhg.de> writes:

> I am searching for a function (call it: var_name) that do something like
> this: 
> 
> >>> V="Hello World"
> >>> var_name(V)
> 'V'

Such a function cannot exist. The argument passed to that var_name
function is the object bound to V, i.e. the string object "Hello
World", *not* the variable itself. So you are asking for the name of
an object, not for the name of the variable. Objects, in general,
don't have names in Python.

Regards,
Martin




More information about the Python-list mailing list