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(
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
> 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
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
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
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