def f(s)
print <name of s> = s
I wish to output "hello=10" for f(hello)
, given that the variable hello has value 10.
The problem is how to get the variable name of the variable, i.e., <name of s>
?
This is for debugging purpose.
Say given a new statement s=2
f(s)
before the new statement will print s=0
if s
is initially 0, f(s)
after the new statement will print s=2
.
I can easily write:
def f(name,value)
print "%s=%s"%(name,str(value))
and use it as f("s",s)
, but that would need me to input two arguments, which is more cumbersome.