Skip to content

Instantly share code, notes, and snippets.

@marsam
Created July 20, 2013 03:20
Show Gist options
  • Select an option

  • Save marsam/6043717 to your computer and use it in GitHub Desktop.

Select an option

Save marsam/6043717 to your computer and use it in GitHub Desktop.
python unicode csv reader
# -*- 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