2

I am trying to allow the user to input their score next to the name of the person on a CSV file. So far, I have got the following which enables me to input names on a new line on the CSV but I cannot find how to create a new column. I am using Python 3.6.3

import csv
file = open ("test results.csv" , 'a')  
name = input('enter your name: ')
file.write(name + "\n")
file.close()
MattR
  • 4,887
  • 9
  • 40
  • 67
  • See https://stackoverflow.com/questions/11070527/how-to-add-a-new-column-to-a-csv-file – xpqz Nov 29 '17 at 17:53
  • Possible duplicate of [How to add a new column to a CSV file?](https://stackoverflow.com/questions/11070527/how-to-add-a-new-column-to-a-csv-file) – MattR Nov 29 '17 at 17:54
  • Or try the pandas library, but depending on what you want to do that could be overkill – Imre_G Nov 29 '17 at 17:55
  • You could extend your current approach just by using `file.write(name + "," + str(score) + "\n")`. But it might be better to use the `csv` module to write this row, to handle quoting automatically (e.g. if the name is "Martin Luther King, Jr.", your approach will create a malformed row). – Matthias Fripp Nov 29 '17 at 18:42

0 Answers0