0
我嘗試寫入CSV文件,但是當我檢查文件時,僅顯示最後一組數據?這怎麼解決? 我原來的代碼是:當我寫入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()
您認爲「toPrint =(name +」,「+ score +」\ n「)'在做什麼? – IanAuld
http://stackoverflow.com/a/2363742/5203702 –