Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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
类型错误:';int';对象没有属性'__获取项目';在Python中枚举_Python_Python 3.x_Python 2.7 - Fatal编程技术网

类型错误:';int';对象没有属性'__获取项目';在Python中枚举

类型错误:';int';对象没有属性'__获取项目';在Python中枚举,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,嗨,我有如下代码 我的元组列表是=[(0,'1.example'),(1,'2.example'),(2,'3.example'),(3,'4.example'),0] Index = [x for x, y in enumerate(tupleList[0]) if y[0] == control] self.list["list_key"].append(tupleList[0][Index[0]][1]) 我的控制变量是1,输入int,我试图到达tuple中的'2.example' 获取

嗨,我有如下代码

我的元组列表是=
[(0,'1.example'),(1,'2.example'),(2,'3.example'),(3,'4.example'),0]

Index = [x for x, y in enumerate(tupleList[0]) if y[0] == control]
self.list["list_key"].append(tupleList[0][Index[0]][1])
我的控制变量是1,输入int,我试图到达tuple中的'2.example'

获取错误

TypeError:Python中的“int”对象没有属性“\uu getitem\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu”

更改我的元组是=
[('E','1examp'),('H','2examp'),'E']

像这样,我的控制变量是“E”,这不是问题,代码正在工作,但我将tupleList=
[(0,'1.example'),(1,'2.example'),(2,'3.example'),(3,'4.example'),0]
和控制变量更改为1,我得到了错误


我如何处理这个元组列表这是因为字符串是可编辑的,而int不是

您可以显式检查整数:

[x for x, y in enumerate(tupleList[0]) if not isinstance(y, int) and y[0] == control]
或者更一般地说:

from typing import Iterable
[x for x, y in enumerate(tupleList[0]) if isinstance(y, Iterable) and y[0] == control]