How to set multiple function keywords at once, in Python 2?
<p>all.</p>

<p>I was wondering if it was possible to set multiple keywords at once (via list?) in a function call.</p>

<p>For example, if you do:</p>

<pre><code>foo, bar = 1, 2
print(foo, bar)
</code></pre>

<p>The output is <code>(1,2)</code>.</p>

<p>For the function</p>

<pre><code>def printer(foo, bar)
    print(foo,bar)
</code></pre>

<p>Is it possible to do something like:</p>

<pre><code>printer([foo, bar] = [1,2])
</code></pre>

<p>where both keywords are being set with a list?</p>

<p>In particular, the reason why I ask is because I have a function that returns two variables, <code>scale</code> and <code>offset</code>:</p>

<pre><code>def scaleOffset(...):
    'stuff happens here

    return [scale, offset]
</code></pre>

<p>I would like to pass both of these variables to a different function that accepts them as keywords, perhaps as a nested call.</p>

<pre><code>def secondFunction(scale=None, offset=None):
    'more stuff
</code></pre>

<p>So far I haven't found a way of doing a call like this:</p>

<pre><code>secondFunction([scale,offset] = scaleOffset())
</code></pre>

<p>To pass args as a list</p>

<pre><code>arg_list = ["foo", "bar"]
my_func(*arg_list)
</code></pre>

<p>To pass kwargs, use a dictionary</p>

<pre><code>kwarg_dict = {"keyword": "value"}    
my_func(**kwarg_dict)
</code></pre>

python arguments parameter-passing kwargs function-call