Function that knows its argument's variable name
greg.ewing at canterbury.ac.nz
Wed Mar 17 00:32:40 CET 2010
Helge Stenström wrote:
> I want to write function that prints a value of a variable, for
> debugging. Like:
> myVariable = "parrot"
> otherVariable = "dead"
Not exactly, but you can come close with a little hackery.
print name, "=", sys._getframe(1).f_locals[name]
fred = 42
mary = "christmas"
More information about the Python-list