Skip to content

Instantly share code, notes, and snippets.

@calistatee
Last active January 27, 2018 01:43
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 calistatee/89457e47fa184f814854dde301cac6f1 to your computer and use it in GitHub Desktop.
Save calistatee/89457e47fa184f814854dde301cac6f1 to your computer and use it in GitHub Desktop.
Python: Write CSV Files
#this is a template for you to write a csv file
import csv
# create a file to open
# 'w' = write mode
# new line = blank
with open('name your csv file', 'w', newline = '') as fp:
# create var
a = csv.writer(fp, delimiter = ',')
data = [['Name', 'Age'],
['Blair', '24'],
['Natalie', '33'],
['Annika', '5']]
a.writerows(data)
# IMPORTANT THINGS TO NOTE:
# 1. do not save your csv files in Sublime Text as csv.py
# 2. make sure there are no csv.py files running in folder of execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment