Calling a function, arguments in a dict ??

Rob Renaud rpgnmets at aol.com
Sun Jun 22 23:53:48 EDT 2003


"Thomas Weholt" <2002 at weholt.org> wrote in message news:<wYpJa.8525$Hb.148440 at news4.e.nsc.no>...
> 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)
> 
>  ???
> 
> Best regards,
> Thomas

This is how you do it.  The real question, what is it called?  How do
you read the function call line in english?

>>> def a(z=0, x=0, y=0):
...     print x, y, z
... 
>>> args = {'z': 1, 'x': 2, 'y': 3}
>>> a(**args)
2 3 1




More information about the Python-list mailing list