0
我有一個帶有鍵/值對的.csv文件。我試圖通過調用我的字典來檢查給定的鍵是否在文件中,但我有一個我不太明白的錯誤。任何幫助感謝!檢查單詞是否在字典中
def Dictionary(x):
wDictionary = open('file.csv', 'r')
for line in wDictionary:
mylist = line.split(',')
def main():
x = input('enter text:')
cd = Dictionary(x)
if x in cd:
print('yes')
main()
錯誤:
Traceback (most recent call last):
File "7.py", line 15, in <module>
main()
File "7.py", line 12, in main
if x in cd:
TypeError: argument of type 'NoneType' is not iterable
您也可以使用模塊「csv」,它使讀取和寫入csv文件非常簡單 – darmat