Last active
January 27, 2018 01:43
-
-
Save calistatee/89457e47fa184f814854dde301cac6f1 to your computer and use it in GitHub Desktop.
Python: Write CSV Files
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
#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