Dictionary as Keyword Arguments

Chris Rebert clp at rebertia.com
Fri Dec 12 01:08:11 CET 2008


On Thu, Dec 11, 2008 at 4:02 PM, bfrederi <brfredericks at gmail.com> wrote:
> I was wondering if I had a dictionary of keywords and values like so:
>
> keyword_arg_dict = {
>    'attribute': 'stone',
>    'contents': 'cave people',
>    'path': '/path/to/cave',
>    'name': 'Ogg's Cave',
>    }
>
> And I had a function that accepted keyword arguments like so:
>
> make_dwelling(
>    attribute='stone',
>    contents='cave people',
>    path='/path/to/cave',
>    name='Ogg's Cave',
>    )
>
> Is there any way I could use my keyword_arg_dict as my keyword args
> for the make_dwelling function, since I am not the creator of the
> make_dwelling function, and need to take that dictionary of key-value
> pairs and turn it into keyword-value arguments for the make_dwelling
> function?

make_dwelling(**keyword_arg_dict)

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com

> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list