-3

Within my code, I need my Name and Score field names to stay the same. However, when adding a row on the last line of code, I want this to append the csv, whereas it's currently overwriting the last entry.

with open("class1.csv", 'w') as csvfile:
    fieldnames = ["Name", "Score"]
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerow({'Name': name, 'Score': score})
Barmar
  • 741,623
  • 53
  • 500
  • 612
Adam
  • 11
  • 1

1 Answers1

2

Use open("class1.csv", 'a') instead of open("class1.csv", 'w')

Peaceful
  • 4,920
  • 15
  • 54
  • 79