Getting actual name of passed arg

Ross Brattain netmgr at
Thu Jun 21 18:19:09 EDT 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

More information about the Python-list mailing list