Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
Python 将列表中的元组转换为独立元组_Python_List_Opencv_Tuples - Fatal编程技术网

Python 将列表中的元组转换为独立元组

Python 将列表中的元组转换为独立元组,python,list,opencv,tuples,Python,List,Opencv,Tuples,我目前有一个名为TrackedPoints的列表,其中包含元组,我可以在调试器中将希望存储在其中的值作为元组 跟踪点:[(350350)、(543345)] 我目前正在使用这段代码来提取我想要的元组 startinex=[TrackedPoints[0]用于TrackedPoints中的x] 这将STARTINEX设置为[(350350)] 如何将startinex转换为元组?我使用了tuple()函数,但它一直像这样返回数据,这在我的应用程序中引发了一个异常: ((350350),) 非常感谢

我目前有一个名为TrackedPoints的列表,其中包含元组,我可以在调试器中将希望存储在其中的值作为元组

跟踪点:[(350350)、(543345)]

我目前正在使用这段代码来提取我想要的元组


startinex=[TrackedPoints[0]用于TrackedPoints中的x]

这将STARTINEX设置为[(350350)]

如何将startinex转换为元组?我使用了tuple()函数,但它一直像这样返回数据,这在我的应用程序中引发了一个异常:

((350350),)


非常感谢您的帮助。

startinex=[TrackedPoints[0]代表TrackedPoints中的x]
:括号之间的部分称为a。这将创建另一个列表

您需要的是从列表中获取第一个元素:
startinex=TrackedPoints[0]

如果
TrackedPoints
-列表为空,则此操作将失败

如果跟踪点:#检查列表是否为空。
STARTINEX=跟踪点[0]
其他:
以适合自己的方式处理错误。

如果您只需要第一点,为什么不这样做:
startinex=TrackedPoints[0]
startinex=TrackedPoints[0]
return
(350350)
@Daniel我做的方式完全错误,感谢您指出,代码现在可以工作了:)