Suppose I have a function that I do not control that looks something like the following:
def some_func(foo, bar, bas, baz):
do_something()
return some_val
Now I want to call this function passing elements from a dict that contains keys that are identical to the arguments of this function. I could do something like:
some_func(foo=mydict['foo'],
bar=mydict['bar'],
bas=mydict['bas'],
baz=mydict['baz'])
Is there some elegant way I could take advantage of the fact that the keys match the parms to do this less verbosely? I know I could pass the whole dict, but let’s say I either don’t want to or can’t change the function to accept a single dict rather than the individual arguments.
Thanks,
Jerry
That’s what
**argument unpacking is for:See also Unpacking argument lists in the Python tutorial.