首页 > 解决方案 > Python - 向 csv 文件添加新行

问题描述

我将新数据附加到 csv 文件中,它添加了信息。下次它添加它时,它错过了一行。我怎样才能让它不会错过一排?(所以它直接附加在最后一条数据的下方?)

当我在 Excel 上打开文件时,它显示为:Laura 99

(额外行)

劳拉 99

代替:

劳拉 99

劳拉 99

记事本

Excel

import csv

with open ("scoreboard.csv", "a") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(["Laura", "99"])
print ("The New score has been added to the score sheet")

标签: pythoncsv

解决方案


推荐阅读