0

I try to write to a CSV file but when i check the file, only th last set of data is displayed? How can this be fixed? my original code is:

highscores=open("Highscores.csv","w")
toPrint=(name+","+score+"\n")
for z in toPrint:
    highscores.write(z)
highscores.close()

and I also tried this:

toPrint=[]
output=(name+","+score+"\n")
toPrint.append(output)
for z in toPrint:
    highscores.write(z)
 highscores.close()
Zak
  • 43
  • 4

1 Answers1

0

You need to open the file in "Append" mode instead of the "Write". Your code will remain the same only the following line will change:

highscores=open("Highscores.csv","a")
Abhinav Arora
  • 3,281
  • 18
  • 20