Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python2中从列表中获取所有项_Python_List_Abaqus - Fatal编程技术网

如何在Python2中从列表中获取所有项

如何在Python2中从列表中获取所有项,python,list,abaqus,Python,List,Abaqus,我将Python 2.7与Simulia Abaqus(6.14)结合使用。 我已按以下格式定义了三维坐标列表: selection_points = [(( 1, 2, 3), ), (( 4, 5, 6), ), ((7, 8, 9), )] 我需要使用选择点中的所有坐标作为模型的输入。我需要每个单独的坐标点,所以不是所有坐标点都作为一个列表。例如,对于以三个坐标作为输入的Abaqus函数(Abaqus_函数),我可以执行以下操作: Abaqus_function(selection_po

我将Python 2.7与Simulia Abaqus(6.14)结合使用。 我已按以下格式定义了三维坐标列表:

selection_points = [(( 1, 2, 3), ), (( 4, 5, 6), ), ((7, 8, 9), )]
我需要使用选择点中的所有坐标作为模型的输入。我需要每个单独的坐标点,所以不是所有坐标点都作为一个列表。例如,对于以三个坐标作为输入的Abaqus函数(Abaqus_函数),我可以执行以下操作:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2])
arguments = ["arg1", "arg1", "arg3"]
print(*arguments)
实际上,这看起来像:

Abaqus_function(((1, 2, 3), ), ((4, 5, 6), ), ((7, 8, 9), ))
现在,如果选择点包含20或100个坐标点怎么办。我怎么能不写信就给他们每个人打电话:

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

Selection\u points[1:-1]
不是办法,我不想要其他列表。因此,
str(选择点)[1:-1]
也不是一个选项。

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

Albaqus_Function(*coord_list[0:n])
其中n是最后一个索引+1

*args符号的用法如下:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2])
arguments = ["arg1", "arg1", "arg3"]
print(*arguments)
这相当于:

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

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

不清楚“获取”是什么意思。给我们一个包含三个或四个点的示例列表以及您想要的输出。为什么在第一个选择点中有两个x坐标和一个y坐标?“我不想要另一个列表”-那么您到底想要什么?前100项只是选择点[:100],但这是一个列表。我很确定这是一个变量或变相的列表解包问题。或者是一个。我不太明白这是怎么回事。你能告诉我这是怎么处理的吗?例如,使用显示打印的虚拟函数。谢谢。@Amit Gold,非常感谢,这正是我的意思。我不熟悉*args符号。现在有没有一种方法可以为特定的项目创建例外?假设我想要第0项到第10项,而不是第4项?您只需在发送带有符号的列表之前相应地更改列表。在我所做的工作中,我只是在同一行中更改了它,因为
[0:n]
创建了另一个列表并发送该列表。在您的示例中,您可以执行
*(args[0:4]+args[5:11])
,但这是不可读的。