Skip to content

Instantly share code, notes, and snippets.

@alonisser
Last active December 13, 2015 20:28
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 alonisser/4970534 to your computer and use it in GitHub Desktop.
Save alonisser/4970534 to your computer and use it in GitHub Desktop.
python 2.7 csv reader the supports unicode (hebrew)
#based on a stackoverflow answer, I currently can't find.
import csv
def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
"""
helper function: a generic csv reader function adapted to unicode
"""
unicode_reader = csv.reader(utf8_data, dialect=dialect, encoding = 'windows-1255', **kwargs)# opening the file with python csv reader
for row in unicode_reader:
#iterating over the ascii data from csv reader and return windows-1255 (or other encoding) encoded rows
yield [unicode(cell, encdoding) for cell in row] #a list comprehension iterating over cells in row and return a list ofunicode encoded cel
@alonisser
Copy link
Author

based on a stackoverflow answer, I currently can't find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment