Dynamically pass a function arguments from a dict
Dan Eloff
dan.eloff at gmail.com
Wed Feb 23 18:50:16 EST 2005
You can take a dictionary of key/value pairs and pass it to a function as
keyword arguments:
def func(foo,bar):
print foo, bar
args = {'foo':1, 'bar':2}
func(**args)
will print "1 2"
But what if you try passing those arguments to a function
def func2(bar,zoo=''):
print bar, zoo
How can you determine that func2 will only accept
bar and zoo, but not foo and call the function with
bar as an argument?
I know CherryPy does this, but it's not obvious from the source
how they pulled it off.
-Dan
More information about the Python-list
mailing list