[英]TypeError: argument of type 'NoneType' is not iterable python
I keep getting this error for like 20 "if ntext[x] in dictionary:". 我不断收到此错误,例如20“ if ntext [x] in dictionary:”。 The program converts text talk into english.
该程序将文本对话转换为英语。
import csv
def CreateDictionary ():
fo = open("textToEnglish2014.csv" , "r")
dictonary = {}
reader = csv.reader(fo)
for row in reader:
dictionary[row[0]] = row[1]
return dictionary
def main():
dictionary = CreateDictionary()
y = "y"
while y == "y":
text = input("Enter text to which you would like conversion: ")
text = text.lower()
ntext = text.split(" ")
new_text = ""
x = 0
while x < len(ntext):
if ntext[x] in dictionary:
new_text = new_text + dictionary[ntext[x]] + " "
else:
export = export + "NF "
x += 1
print (new_text)
y = input("Continue conversion? y or q ")
main()
dictonary = {}
should be 应该
dictionary = {}
note the spelling 注意拼写
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.