Calling a function, arguments in a dict ??

Erik Max Francis max at alcyone.com
Sun Jun 22 19:31:28 EDT 2003


Thomas Weholt wrote:

> If I got a dictionary with a bunch of key/values I want to use as
> named
> arguments for a function, how do I do that?
> 
> Say we got a function a, takes three parameters; x,y,z. In my
> dictionary I
> got {'z': 1, 'x': 2, 'y': 3}. How can I create some code that will
> call it
> like this :
> 
> a(z =1, x=2, y=3)

>>> def f(x, y, z):
...  print x, y, z
... 
>>> d = {'x': 1, 'y': 2, 'z': 3}
>>> f(**d)
1 2 3

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ ... Not merely peace in our time, but peace for all time.
\__/  John F. Kennedy




More information about the Python-list mailing list