【发布时间】:2022-01-04 05:01:00
【问题描述】:
晚上好,我有一个问题是我必须制作 2 个 python 文件,其中 TestFiltrado 过滤 .csv 文件的列并且恰好有 2 列),另一个称为:Testdefiltrado 打印这 2 列,但我明白了错误。
测试过滤器:
Almacenamiento_de_datos = namedtuple('DESAPARECIDOS_INDIA_2018_2020','Tipo_de_sangre,Nombres,Genero,Cuerpo,Distrito,'
#where are the columns CSV FILE
'DENUNCIADO,Estatura,Edad,Cuando_Desparecio')
def Archivo_Csv(Archivo):
with open(Archivo, encoding = 'utf-8') as f:
lineador = csv.reader(f, delimiter=";")
next(lineador)
lista =[(Almacenamiento_de_datos(Tipo_de_sangre, Nombres, Genero, Cuerpo, Distrito, DENUNCIADO, float(Estatura), int(Edad),
Cuando_Desparecio)for Tipo_de_sangre, Nombres, Genero, Cuerpo, Distrito,DENUNCIADO,
Estatura, Edad, Cuando_Desparecio in lineador)]
return lista
#open the csv file and access it to
Storage which is namedtuple save it in the variable l i s t a
def Todos_Los_nombres (lista):
for i in lista:
Nom = next(i['Nombres'], i ['Edad'])
return Nom
#en list iterate and find me the columns EN: h o m b r e s, (int) E d a d
这就是调用它的代码
def TestFiltrador (Desaparecidoscsv):
Nom= Todos_Los_nombres(Desaparecidoscsv)
print("Los nombres y sus edad son : ",Nom)
## Nom : iterates the first code above and prints
是这个错误
Nom = next(i['Nombres'], i ['Edad'])
TypeError: 'generator' object is not subscriptable
我该怎么办? 我希望他们能帮助我,感谢看到我的问题
【问题讨论】:
-
那不是编译错误,那是运行时错误
-
尝试论坛中的 2 种解决方案,我无法在我的情况下没有遭受。