如何从 Python 2 中的列表中获取所有项目

How to get all items from a list in Python 2

我将 Python 2.7 与 Simulia Abaqus (6.14) 结合使用。 我已经按照以下格式定义了一个 3-D 坐标列表:

selection_points = [(( 1, 2, 3), ), (( 4, 5, 6), ), ((7, 8, 9), )]

我需要使用 selection_points 中的所有坐标作为我模型的输入。我需要单独的每个坐标点,所以不是所有的都作为一个列表。例如,对于将三个坐标作为输入的 Abaqus 函数 (Abaqus_function),我可以执行以下操作:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2])

实际上看起来像:

Abaqus_function(((1, 2, 3), ), ((4, 5, 6), ), ((7, 8, 9), ))

现在如果 selection_points 包含 20 或 100 个坐标点怎么办。我怎么能不写就给他们一个个打电话:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2], 
                selection_points[3], ... selection_points[99])

Selection_points[1 : -1] 不是要走的路,我不想要另一个列表。因此 str(selection_points)[1: -1] 也不是一个选项。

您要做的是将列表的元素解压缩为参数。可以这样做:

Albaqus_Function(*coord_list[0:n])

其中 n 是最后一个索引 +1。

*args 符号的用法如下:

arguments = ["arg1", "arg1", "arg3"]
print(*arguments)

这相当于:

print("arg1", "arg2", "arg3")

当您不确定需要多少参数时,这很有用。