Getting actual name of passed arg

Ross Brattain netmgr at canterburycrest.org
Fri Jun 22 00:19:09 CEST 2001


I am thinking about a debugging function that takes an arg and prints 
the arg name and value.

a = 1

def foo(b):
	print "<NAME OF ARG>:" + b

foo(a)  would print   "a: 1"

Mostly for simple types.  I know you can get the id via id(), but that 
doesn't work for pass by value.  I can't find anything in inspect that 
would work.  I imagine it isn't possible because most things are passed 
by value.  Is there someway of mapping id() to variable name.  So that I 
could define

def bar(b, c):
	print str(b) + str(c)

bar(a, id(a))


Ross Brattain
netmgr at canterburycrest.org




More information about the Python-list mailing list