How to generate a `kwargs` list?

Paul Manta picture Paul Manta · Sep 15, 2011 · Viewed 9.8k times · Source

From an external file I generate the following dictionary:

mydict = { 'foo' : 123, 'bar' : 456 }

Given a function that takes a **kwargs argument, how can generate the keyword-args from that dictionary?

Answer

Falmarri picture Falmarri · Sep 15, 2011
def foo(**kwargs):
    pass

foo(**{ 'foo' : 123, 'bar' : 456 })