<p>Say I have the following methods:</p>

<pre><code>def methodA(arg, **kwargs):
    pass

def methodB(arg, *args, **kwargs):
    pass
</code></pre>

<p>In methodA I wish to call methodB, passing on the kwargs. However, it seems that if I define <code>methodA</code> as follows, the second argument will be passed on as positional rather than named variable arguments.</p>

<pre><code>def methodA(arg, **kwargs):
    methodB("argvalue", kwargs)
</code></pre>

<p>How do I make sure that the **kwargs in methodA gets passed as **kwargs to methodB?</p>

[{'answer_id': 51414, 'author': 'Staale', 'author_id': 3355, 'author_profile': 'https://Stackoverflow.com/users/3355', 'pm_score': 1, 'selected': False, 'text': '<p>Some experimentation and I figured this one out:</p>\n\n<p>def methodA(arg, **kwargs):\n    methodB("argvalue", **kwargs)</p>\n\n<p>Seems obvious now...</p>\n'}, {'answer_id': 51415, 'author': 'Cristian', 'author_id': 680, 'author_profile': 'https://Stackoverflow.com/users/680', 'pm_score': 6, 'selected': True, 'text': '<p>Put the asterisks before the kwargs variable. This makes Python pass the variable (which is assumed to be a dictionary) as keyword arguments.</p>\n\n<pre><code>methodB("argvalue", **kwargs)\n</code></pre>\n'}, {'answer_id': 63943, 'author': 'Sebastian Rittau', 'author_id': 7779, 'author_profile': 'https://Stackoverflow.com/users/7779', 'pm_score': 2, 'selected': False, 'text': '<p>As an aside: When using functions instead of methods, you could also use functools.partial:</p>\n\n<pre><code>import functools\n\ndef foo(arg, **kwargs):\n    ...\n\nbar = functools.partial(foo, "argvalue")\n</code></pre>\n\n<p>The last line will define a function "bar" that, when called, will call foo with the first argument set to "argvalue" and all other functions just passed on:</p>\n\n<pre><code>bar(5, myarg="value")\n</code></pre>\n\n<p>will call</p>\n\n<pre><code>foo("argvalue", 5, myarg="value")\n</code></pre>\n\n<p>Unfortunately that will not work with methods.</p>\n'}]
['https://Stackoverflow.com/questions/51412', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3355/']