我尝试写入CSV文件但是当我检查文件时,只显示最后一组数据?怎么解决这个问题? 我原来的代码是:
highscores=open("Highscores.csv","w")
toPrint=(name+","+score+"\n")
for z in toPrint:
highscores.write(z)
highscores.close()
我也试过这个:
toPrint=[]
output=(name+","+score+"\n")
toPrint.append(output)
for z in toPrint:
highscores.write(z)
highscores.close()
答案 0 :(得分:0)
您需要以“附加”模式而不是“写入”打开文件。您的代码将保持不变,只有以下行会发生变化:
highscores=open("Highscores.csv","a")