enter image description here我正在使用辅助函数读取文件,将每一行放入字典中。每个字典必须放入一个列表然后返回。每次我尝试返回列表时,python都会停止响应
def readData(filename='steak-risk-survey.csv', fields=fields, values=values):
def helper(row, header):
b = {header[i]: row[i] for i in range(len(header))}
return b
list1 = []
with open(filename) as csvDataFile:
csvReader = csv.reader(csvDataFile)
row1 = next(csvReader)
row = next(csvReader)
for row in csvReader:
list1.append(helper(row, row1))
return list1
这是默认参数引用的文件