TypeError:类型' NoneType'的参数不是可迭代的python

时间:2014-09-23 01:31:23

标签: python python-3.x dictionary nonetype

我继续像20"如果词典中的ntext [x]那样得到这个错误:"。该程序将文本谈话转换为英语。

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()

1 个答案:

答案 0 :(得分:2)

dictonary = {}

应该是

dictionary = {}

注意拼写