Skip to main content

Python2's stdlib csv module is nice, but it doesn't support unicode. This module is a drop-in replacement which *does*.

Project description

The unicodecsv is a drop-in replacement for Python 2’s csv module which supports unicode strings without a hassle.

More fully

Python 2’s csv module doesn’t easily deal with unicode strings, leading to the dreaded “‘ascii’ codec can’t encode characters in position …” exception.

You can work around it by encoding everything just before calling write (or just after read), but why not add support to the serializer?

>>> import unicodecsv
>>> from cStringIO import StringIO
>>> f = StringIO()
>>> w = unicodecsv.writer(f, encoding='utf-8')
>>> w.writerow((u'é', u'ñ'))
>>> f.seek(0)
>>> r = unicodecsv.reader(f, encoding='utf-8')
>>> row = r.next()
>>> print row[0], row[1]
é ñ

Note that unicodecsv expects a bytestream, not unicode – so there’s no need to use codecs.open or similar wrappers. Plain open will do.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unicodecsv-0.14.0.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file unicodecsv-0.14.0.tar.gz.

File metadata

  • Download URL: unicodecsv-0.14.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for unicodecsv-0.14.0.tar.gz
Algorithm Hash digest
SHA256 495871db660eb0519e351cbbac02996448071e726b2523d4e01bc51ecb8c7795
MD5 ae2aaff1c2de7b15c741ac394f75a429
BLAKE2b-256 f056e6c92f3349b9e759f5fb199fcc174cb3f5b33c08f47e6b341e4ce15569c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page