Skip to content

Instantly share code, notes, and snippets.

@sboisson
Created May 23, 2014 14:56
Show Gist options
  • Save sboisson/0272707f96bd17ed976c to your computer and use it in GitHub Desktop.
Save sboisson/0272707f96bd17ed976c to your computer and use it in GitHub Desktop.
Correctly reading CSV files in arbitrary encodings
import codecs
import csv
def csv_unireader(f, encoding="utf-8"):
for row in csv.reader(codecs.iterencode(codecs.iterdecode(f, encoding), "utf-8")):
yield [e.decode("utf-8") for e in row]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment