转换列表在Python * ARGS [英] Converting list to *args in Python

查看:153
本文介绍了转换列表在Python * ARGS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,我怎么转换列表* ARGS?

In Python, how do I convert a list to *args?

我需要知道,因为函数

scikits.timeseries.lib.reportlib.Report.__init__(*args)

想为* ARGS通过了若干time_series对象,而我有时间序列对象的列表。

wants several time_series objects passed as *args, whereas I have a list of timeseries objects.

任何帮助是极大AP preciated:)

Any help is greatly appreciated :)

推荐答案

您可以使用 * 运营商之前迭代,以函数调用内展开。例如:

You can use the * operator before an iterable to expand it within the function call. For example:

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

(注意 * timeseries_list

Python文档

如果语法*前pression出现在函数调用,前pression
  计算结果必须是一个可迭代。从这个迭代的元素处理
  就好像它们是额外的位置参数;如果有
  位置参数X1,...,XN,和前pression计算结果为
  序列Y1,...,YM,这相当于用M + N的位置的呼叫
  参数X1,...,XN,Y1,...,y M的

If the syntax *expression appears in the function call, expression must evaluate to an iterable. Elements from this iterable are treated as if they were additional positional arguments; if there are positional arguments x1, ..., xN, and expression evaluates to a sequence y1, ..., yM, this is equivalent to a call with M+N positional arguments x1, ..., xN, y1, ..., yM.

这篇关于转换列表在Python * ARGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆