Last active
December 13, 2015 20:28
-
-
Save alonisser/4970534 to your computer and use it in GitHub Desktop.
python 2.7 csv reader the supports unicode (hebrew)
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
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on a stackoverflow answer, I currently can't find.