首先导入库
import csv
读取csv
# 传入csv文件 返回多维list
def readCSV(file):
with open(file, "r") as f:
reader = csv.reader(f)
rows = [row for row in reader]
return rows
写入csv
# data:多维维list,每个子项为一行 file为写入的csv文件名
def write2CSV(data, file):
with open(file,'w',newline='') as csvfile:
writer = csv.writer(csvfile)
for row in data:
writer.writerow(row)