How to get all items from a list in Python 2
我使用的是Python2.7和SimuliaAbaqus(6.14)的组合。我定义了以下格式的三维坐标列表:
1  | selection_points = [(( 1, 2, 3), ), (( 4, 5, 6), ), ((7, 8, 9), )]  | 
我需要使用选择点中的所有坐标作为模型的输入。我需要每个单独的坐标点,所以不是所有坐标点都作为列表。例如,对于以三个坐标作为输入的ABAQUS函数(ABAQUS_函数),我可以执行以下操作:
1  | Abaqus_function(selection_points[0], selection_points[1], selection_points[2])  | 
号
实际上,这看起来像:
1  | Abaqus_function(((1, 2, 3), ), ((4, 5, 6), ), ((7, 8, 9), ))  | 
如果选择点包含20或100个坐标点怎么办?我怎么能不写信就给他们每个人打电话呢?
1 2  | Abaqus_function(selection_points[0], selection_points[1], selection_points[2],  selection_points[3], ... selection_points[99])  | 
。
我不想再列一个单子。因此,
您要做的是将列表中的元素解包为参数。可以这样做:
1  | Albaqus_Function(*coord_list[0:n])  | 
其中n是最后一个索引+1。
*args表示法用于以下内容:
1 2  | arguments = ["arg1","arg1","arg3"] print(*arguments)  | 
号
这相当于:
1  | print("arg1","arg2","arg3")  | 
当您不确切知道需要多少参数时,这很有用。