unpacking function argument [duplicate]
Solution 1:
You are looking for the *args
argument syntax:
>>> def foo(bar, baz, spam):
... print bar, baz, spam
...
>>> arguments = [1, 2, 3]
>>> foo(*arguments)
1, 2, 3
When passing arguments to a callable, any expression preceded by a *
asterix, is interpreted as a sequence of positional arguments, and expanded to be passed on as separate arguments to the called object (function, method, etc.).
For your example that would be:
func1(*func2(...))
There is a keyword equivalent using **
double asterixes (takes a mapping), and you can use the same syntax in function signatures too.
See the documentation on call expressions, and for the function signature mirror syntax, the documentation on function definitions.
Solution 2:
It's called argument unpacking and is written as:
func1(*func2(...))
Refer: https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists