Dictionary as Keyword Arguments

B

bfrederi

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?
 
C

Chris Rebert

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
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top