Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.