1
我一直得到這個錯誤的像20「if ntext [x] in dictionary:」。該程序將文字說話轉換成英語。TypeError:'NoneType'類型的參數是不可迭代的python
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()
是在CreateDictionary()意味着要縮進這樣的 「回報」?如果是這樣,CreateDictionary將在第一行之後返回。 – 2014-09-23 01:36:04
如果有第一行,它將只返回字典;如果沒有,則會從函數的末尾落下並返回'None'。 – user2357112 2014-09-23 01:59:17