Re: Function that knows its argument's variable name

2010-03-17 Thread Helge Stenström
Thank you to all who answered. Inspection is apparently possible, but too complex for me. Greg's solution does what I want, inserting "" is no problem. /Helge > Not exactly, but you can come close with a little hackery. > > import sys > > def print_var(name): >    print name, "=", sys._getframe(

Re: Function that knows its argument's variable name

2010-03-17 Thread Tino Wildenhain
Hi, Am 14.03.2010 12:58, schrieb Helge Stenström: I want to write function that prints a value of a variable, for debugging. Like: with myVariable = "parrot" otherVariable = "dead" probe(myVariable) probe(otherVariable) instead of the longer print "myVariable = ", myVariable print "otherVa

Re: Function that knows its argument's variable name

2010-03-16 Thread Phlip
> Yet, the answer to your question is not quite absolutely "no".  Python > has lots of introspection capabilities, including, perhaps, getting at > and parsing the original code to find the call.    But there's nothing > direct for what you want. > > Gary Herron Below my sig is one shot at it; whi

Re: Function that knows its argument's variable name

2010-03-16 Thread Gregory Ewing
Helge Stenström wrote: I want to write function that prints a value of a variable, for debugging. Like: myVariable = "parrot" otherVariable = "dead" > probe(myVariable) probe(otherVariable) Not exactly, but you can come close with a little hackery. import sys def print_var(name): print

Re: Function that knows its argument's variable name

2010-03-14 Thread Gary Herron
Helge Stenström wrote: I want to write function that prints a value of a variable, for debugging. Like: with myVariable = "parrot" otherVariable = "dead" probe(myVariable) probe(otherVariable) instead of the longer print "myVariable = ", myVariable print "otherVariable = ", otherVariable I

Function that knows its argument's variable name

2010-03-14 Thread Helge Stenström
I want to write function that prints a value of a variable, for debugging. Like: with myVariable = "parrot" otherVariable = "dead" probe(myVariable) probe(otherVariable) instead of the longer print "myVariable = ", myVariable print "otherVariable = ", otherVariable Is that even possible? Th