Can you obtain names from parent scope?
wsadkin at nameconnector.com
Fri Jan 17 16:51:35 CET 2003
I want to write a function that takes an arbitrary set of objects,
and prints them in the form "name = <value>." That is, I want to be
able to say:
>>> a = 'hi!'
a = hi!
>>> b = 2
b = 2
However I can't make this work, because objects don't have any
intrinsic name, and if I write a function of the form
>>> def dbgval(*args):
then dbgval() only knows the arguments objects as belonging to the
list 'args', and I can't find any way to determine what the names
were in the parent's local scope when the function was called.
Is there any way for a function to retrieve this information?
Thanks in advance,
More information about the Python-list