Search code examples
pythonsplatkeyword-expansion

Can you combine keyword argument expansion with regular keyword arguments?


What I want to do is this:

logged_in = {
    'logged_in': True,
    'username' : 'myself',
    }
print render_template('/path/to/template.html',
    **logged_in,
    title = 'My page title',
    more  = 'even more stuff',
    )

But that doesn't work. Is there any way to combine a dictionary expansion with explicit arguments, or would I need to define the explicit arguments in second dictionary, merge the two, and expand the result?


Solution

  • Keyword expansion must be at the end.

    print render_template('/path/to/template.html',
        title = 'My page title',
        more  = 'even more stuff',
        **logged_in
    )