python读写csv文件
读取csv文件
代码
import csv
with open('总分.csv', 'r', encoding='gbk', newline='') as f:
# 读取文件所有信息
LIST = csv.reader(f)
content2 = list(LIST)
for i in LIST:
f.close()
print(content2)
运行截图
写csv文件
代码
import csv
with open('history.csv', "w", encoding='gbk', newline="") as f:
csv_writer = csv.writer(f)
csv_writer.writerow(["类型", "时间", "金额", "备注"])
csv_writer.writerow(["类型1", "时间2", "金额3", "备注4"])