我正在尝试将 .csv 文件导入字典。我的麻烦是,当我尝试从 dict 读取时,我没有得到输出?为什么??
.csv 文件如下所示:
F59241,GG1212
F65563,QQ434
F59226,WW343
F69215,CC434
我尝试过的是:
import csv
with open('myfile.csv', mode='r') as infile:
reader = csv.reader(infile,)
with open('mtfile.csv', mode='w') as outfile:
writer = csv.writer(outfile)
DICT = {rows[0]:rows[1] for rows in reader}
n = ['F59241', 'F65563', 'F59226', 'F69215']
for key in n:
if DICT.get(key):
print ((key) + ' : ' + DICT[key])
else:
print((key) + ' : ' + "Not Available")
谁能告诉我我做错了什么?谢谢