apply for keywords

Skip Montanaro skip at
Wed Jul 11 13:44:44 EDT 2001

    Curtis> Can you use "apply" to pass keywords?

Yup.  Third argument is an optional dictionary representing the keyword args
to the function you're calling:

    apply(foo, (), {"bar": 1})

Note that since 2.0 Python has a nice shortcut that allows you to call
functions taking variable arguments from other similarly signatured
functions.   So, instead of

    apply(spam, args, kwds)

where args is a tuple and kwds is a dict, you can write:

    spam(*args, **kwds)

Skip Montanaro (skip at

More information about the Python-list mailing list