Created
July 20, 2013 03:20
-
-
Save marsam/6043717 to your computer and use it in GitHub Desktop.
python unicode csv reader
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
| # -*- coding: utf-8 -*- | |
| # | |
| # http://stackoverflow.com/a/904085 | |
| import csv | |
| def UnicodeDictReader(utf8_data, **kwargs): | |
| csv_reader = csv.DictReader(utf8_data, **kwargs) | |
| for row in csv_reader: | |
| yield {key: unicode(value, 'utf-8') for key, value in row.iteritems()} | |
| def unicode_csv_reader(utf8_data, **kwargs): | |
| csv_reader = csv.reader(utf8_data, **kwargs) | |
| for row in csv_reader: | |
| yield [unicode(cell, 'utf-8') for cell in row] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment