我想将 csv.reader 中的内容转换为字典。我实施了这篇文章中的说明 Add new keys to a dictionary?但我不断得到IndexError: list index out of range
。我怎样才能解决这个问题?
import wx
import csv
info = csv.reader(open('report.csv', 'rb'),delimiter=',')
length = 0
info_list = []
for row in info: #search each row in the report
info_list.append([length,row[1],row[4]])
length = length + 1
print length
dict_info = {}
rows = 0
counter = 0
while counter < length:
for item in info_list:
dict_info[item[rows]] = [item[rows + 1], item[rows + 2]]
rows = rows + 3
counter = counter + 1
print dict_info