Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Created February 18, 2015 12:59
Show Gist options
  • Save DenisCarriere/5c2405d1c70980ab56cc to your computer and use it in GitHub Desktop.
Save DenisCarriere/5c2405d1c70980ab56cc to your computer and use it in GitHub Desktop.
Reading CSV file
import csv
"""
filename.csv
============
first,second
hello,world
"""
# Standard CSV Reading
with open('filename.csv') as f:
reader = csv.reader(f)
for line in reader:
print line
# Dictionary CSV Reading
with open('filename.csv') as f:
reader = csv.DictReader(f)
for line in reader:
print line
"""
out
===
['first', 'second']
['hello', 'world']
{'second': 'world', 'first': 'hello'}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment