Function that knows the names of its actual parameters

Stefan Franke spamfranke at bigfoot.de
Fri Jun 16 13:50:20 EDT 2000


I found myself in need for the following functionality a couple of times:

>>> a=1
>>> b="foo"
>>> c=b
>>> magic(c, b, a)
{'a': 1, 'b': 'foo', 'c': 'foo'}

that is, a function that goes one step further than **dict arguments and returns
a dictionary with names and values of its actual parameters.
It's useful every time one tries to write generators for Python or other code (right
now I'm writing some SQL code emitting functions).

I guess it would be possible to implement using the a similar trick than the one 
to find out the caller's name - generating an exception and examining the
traceback.
But maybe someone knows a more efficient solution or one that has chances 
to work with future Python version as well?

Stefan




More information about the Python-list mailing list