Skip to content

Instantly share code, notes, and snippets.

@language-engineering
Created October 3, 2012 18:04
Show Gist options
  • Select an option

  • Save language-engineering/3828658 to your computer and use it in GitHub Desktop.

Select an option

Save language-engineering/3828658 to your computer and use it in GitHub Desktop.
import csv
#Provide a list, where every element in the list corresponds to a row of the spreadsheet
#Every element in the list is another list, whose elements correspond to the columns of that row
data = [[2,3,3],[4,3,5],[2,1,4]]
#Write the data to a CSV file, which a spreadsheet program can open
with open("file_name.csv","wb") as outputfile:
writer = csv.writer(outputfile)
writer.writerows(data)
#Read in the data of a CSV for further processing in Python
with open("file_name.csv","rb") as inputfile:
reader = csv.reader(inputfile)
for row in reader:
print row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment