Last active
May 22, 2018 10:52
-
-
Save richardbwest/3df3c05ebb967c78809665207bfaf19b to your computer and use it in GitHub Desktop.
Simple example of how to write to a CSV File using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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