In Python, how do I convert a list to *args
?
I need to know because the function
scikits.timeseries.lib.reportlib.Report.__init__(*args)
wants several time_series objects passed as *args
, whereas I have a list of timeseries objects.
This question is related to
python
list
arguments
function-call
*args
just means that the function takes a number of arguments, generally of the same type.
Check out this section in the Python tutorial for more info.
yes, using *arg passing args to a function will make python unpack the values in arg and pass it to the function.
so:
>>> def printer(*args):
print args
>>> printer(2,3,4)
(2, 3, 4)
>>> printer(*range(2, 5))
(2, 3, 4)
>>> printer(range(2, 5))
([2, 3, 4],)
>>>
Source: Stackoverflow.com