Function that knows its argument's variable name
h.stenstrom at gmail.com
Sun Mar 14 12:58:07 CET 2010
I want to write function that prints a value of a variable, for
myVariable = "parrot"
otherVariable = "dead"
instead of the longer
print "myVariable = ", myVariable
print "otherVariable = ", otherVariable
Is that even possible?
The function would look like
nameOfVar = someMagic(var)
print nameOfVar, " = ", var
but can someMagic(var) find the variable name? Is that possible?
More information about the Python-list