Passing all elements of tuple in function 1 (from *args) into function 2 (as *args) in python
<p>I am writing a function to take *args inputs, assess the data, then pass all inputs to the next appropriate function (align), also taking *args</p>

<p>*args seems to be a tuple. I have tried various ways of passing each element of the tuple into the next function, the latest two being:</p>

<pre><code>            for x in args:
                align(*x)
</code></pre>

<p>and</p>

<pre><code>            for x in args:
                align(args[0:len(args)])    
</code></pre>

<p>You "unpack them" with <code>*args</code>.  Then the receiving function can mop them up into a tuple again (or not!).  </p>

<p>These examples should enlighten things:   </p>

<pre><code>&gt;&gt;&gt; def foo(*f_args):
...     print('foo', type(f_args), len(f_args), f_args)
...     bar(*f_args)
...     
&gt;&gt;&gt; def bar(*b_args):
...     print('bar', type(b_args), len(b_args), b_args)
...     
&gt;&gt;&gt; foo('a', 'b', 'c')
('foo', &lt;type 'tuple'&gt;, 3, ('a', 'b', 'c'))
('bar', &lt;type 'tuple'&gt;, 3, ('a', 'b', 'c'))
</code></pre>

<p>Now, let's redefine <code>bar</code> and break the argspec:</p>

<pre><code>&gt;&gt;&gt; def bar(arg1, arg2, arg3):
...     print('bar redefined', arg1, arg2, arg3)
...     
&gt;&gt;&gt; foo('a', 'b', 'c')
('foo', &lt;type 'tuple'&gt;, 3, ('a', 'b', 'c'))
('bar redefined', 'a', 'b', 'c')
&gt;&gt;&gt; foo('a', 'b')
('foo', &lt;type 'tuple'&gt;, 2, ('a', 'b'))
---&gt; TypeError: bar() takes exactly 3 arguments (2 given)
</code></pre>

python function tuples args