import csv
def parseCSVFileStr(data):
"""
将csv转换为 [{},{},{},{},{},{},] 形式的列表
"""
titleFlag = 0
ldata = []
ltitle = []
data = data.replace('"', '')
for row in data.split("\r\n"):
if titleFlag == 0:
for cell in row.split(","):
ltitle.append(cell.upper())
titleFlag = 1
else:
d = {}
i = 0
for cell in row.split(","):
d[ltitle[i]] = cell
i = i+1
ldata.append(d)
return ldata
f = csv.read('./filename.xxx')
fdata = f.read()
tmpdata = parseCSVFileStr(fdata.decode('GBK'))
标签:ldata,读取,Python,cell,split,ltitle,CSV,data,row
From: https://www.cnblogs.com/congxinglong/p/14780233.html