Requiring arguments to be passed as keyword arguments
Greg Ewing
greg.ewing at compaq.com
Thu Oct 7 10:32:33 EDT 1999
Michael Haggerty wrote:
>
> Hi,
>
> Sometimes I would like to write functions with arguments that are
> REQUIRED to be passed as keyword arguments
Let's approach this in a more general way. First,
introduce dictionary unpacking:
(foo, bar, baz) = dict
is equivalent to
foo = dict['foo']; bar = dict['bar']; baz = dict['baz']
Then we can write
def wack(a, b, **d):
(x, y, z) = d
Next, if we allow dictionary unpacking in the parameter
list, we get:
def wack(a, b, **(x, y, z)):
...
Greg
More information about the Python-list
mailing list