-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
  • 669,327
  • 51
  • 454
  • 560
Adam
  • 11

1 Answers1

1

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

Peaceful
  • 4,202
  • 12
  • 51
  • 73