Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Unicode Dict CSV Reader
# -*- coding: utf-8 -*-
:copyright: (C) 2013-2015 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
import csv
class UnicodeDictReader(csv.DictReader):
def __init__(self, csvfile, *args, **kwargs):
"""Allows to specify an additional keyword argument encoding which
defaults to "utf-8"
self.encoding = kwargs.pop('encoding', 'utf-8')
self, csvfile, *args, **kwargs
def next(self):
rv =
return dict((
(k, v.decode(self.encoding).rstrip() if v else v) for k, v in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.