![](/img/trans.png)
[英]Python chatbot “TypeError: argument of type 'NoneType' is not iterable”
[英]TypeError: argument of type 'NoneType' is not iterable python
我不斷收到此錯誤,例如20“ if ntext [x] in dictionary:”。 該程序將文本對話轉換為英語。
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 = {}
應該
dictionary = {}
注意拼寫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.