views:

72

answers:

3

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.

Any help is greatly appreciated :)

+8  A: 

Have you tried:

timeseries_list = [timeseries1 timeseries2 ...]
r = scikits.timeseries.lib.reportlib.Report(*timeseries_list)

(notice the * before timeseries_list)

Bryan Oakley
Forgot this: http://docs.python.org/reference/expressions.html#calls
S.Lott
A: 

*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.

intuited
I think the OP already knows this. The function takes multiple args but they have a single list they want to pass in as multiple args.
Bryan Oakley
@Bryan Oakley: The docs I linked to explain how to do that.
intuited
@intuited: while that's true, the way you worded your answer it sounds like the link points to somewhere else. I think your answer will be more useful if you reword it to address unpacking rather than what *args means.
Bryan Oakley
A: 

yes, using *arg passing args to a func will make python unpack the values in arg and pass it to the func...

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],)
>>> 
Ant