Created
February 18, 2015 12:59
-
-
Save DenisCarriere/5c2405d1c70980ab56cc to your computer and use it in GitHub Desktop.
Reading CSV file
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
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