Skip to content

Instantly share code, notes, and snippets.

@Hootrix
Forked from HintikkaKimmo/who_data.py
Last active August 17, 2019 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hootrix/ba491173cd29ce96ce1b16323c5a2483 to your computer and use it in GitHub Desktop.
Save Hootrix/ba491173cd29ce96ce1b16323c5a2483 to your computer and use it in GitHub Desktop.
handy way to read csv files with unknown csv dialect
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