Created
February 21, 2017 06:10
-
-
Save HintikkaKimmo/9336e2e56136f3e6b3a04b782ce33195 to your computer and use it in GitHub Desktop.
handy way to read csv files with unknown csv dialect
This file contains hidden or 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 | |
import pprint | |
# opens csv file and assingns it to an object | |
with open('data-text.csv') as csvfile: | |
# Use Sniffer to figure out csv dialect | |
dialect = csv.Sniffer().sniff(csvfile.read(1024)) | |
csvfile.seek(0) | |
# pass the dialect to filereader to read the file | |
reader = csv.reader(csvfile, dialect) | |
# print(dialect) | |
# Use for loop to print csv row by row | |
for row in reader: | |
pprint.pprint(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment