Skip to content

Instantly share code, notes, and snippets.

@richardbwest
Last active May 22, 2018 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardbwest/3df3c05ebb967c78809665207bfaf19b to your computer and use it in GitHub Desktop.
Save richardbwest/3df3c05ebb967c78809665207bfaf19b to your computer and use it in GitHub Desktop.
Simple example of how to write to a CSV File using Python
import csv
f = open('scores.csv','a') # 'a' stands for APPEND / ADD TO
# use 'w' if you want to replace the whole file's contents...
writer = csv.writer(f)
fname = input("First name: ")
lname = input("Last name: ")
score = input("Score: ")
row = [fname,lname,score] #Put all the inputs together in a list to make a row.
writer.writerow(row) #Add the row to the scores.csv file
f.close() #Save the file - YOU MUST DO THIS TO SAVE THE CHANGES TO THE FILE!!!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment