CSV 一般写入, 追加改模式w 为a
# -*- coding: utf-8 -*-
import csv
# 头数据
fileHeader = ["name", "score"]
# 内容数据
d1 = ["Wang", "100"]
d2 = ["Li", "80"]
# 写入数据
csvFile = open("instance.csv", "w")
writer = csv.writer(csvFile)
# 分批写入
writer.writerow(fileHeader)
writer.writerow(d1)
writer.writerow(d2)
# 一次写入
writer.writerows([fileHeader, d1, d2])
csvFile.close()