当我用3个整数参数运行下面的代码时
import sys
import numpy as np
fichier=open("vocLemma.tsv")
dico=dict()
borneMin=int(sys.argv[1])
borneMax=int(sys.argv[2])
nbClasseMax=int(sys.argv[3])
cpt=0
error=0
for ligne in fichier:
try:
tab=ligne.split("\t")
mot=tab[0]
freq=map(int, list(tab[1].strip("[").strip("]").replace(" ", "").split(",")))
nbAnnee=int(tab[2])
classes=tab[3]
nbClasse=0
for classe in ["A", "B", "C", "D", "E", "F", "G", "H"]:
if classe in classes:
nbClasse+=1
docTotal=np.sum(np.array(freq))
if not mot.isdigit() and nbAnnee > 1 and docTotal > borneMin and docTotal < borneMax and nbClasse <= nbClasseMax:
dico[tab[0].strip()]=ligne.strip()
cpt+=1
except IndexError:
error+=1
pass
print(cpt)
fichier =open("voc_freqmin"+str(borneMin)+"_docmax"+str(borneMax)+"_classemax"+str(nbClasseMax), "w")
for mot in dico:
fichier.write(dico[mot]+"\n")
fichier.close()
我收到一条错误信息,如:
File "filtre.py", line 25, in <module>
if not mot.isdigit() and nbAnnee > 1 and docTotal > borneMin and docTotal < borneMax and nbClasse <= nbClasseMax:
TypeError: '>' not supported between instances of 'map' and 'int'
但我不知道为什么。有人能帮我吗?谢谢!你知道吗
解决了。我在@randomfigure中添加了这样一个注释,“这是人们在从python2移植到python3时遇到的一个常见错误”(也就是说,使用‘map’)
map
函数返回一个map
对象,而不是一个列表。在此行中:将
freq
定义为map
对象。稍后,当您通过numpy操作传递它时,它仍然只是单个map
对象的数组。这条线:不返回数字,而是返回另一个
map
对象。你知道吗可以使用以下方法修复此问题:
相关问题 更多 >
编程相关推荐