• Stars
    star
    595
  • Rank 74,704 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created almost 14 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python2's stdlib csv module is nice, but it doesn't support unicode. This module is a drop-in replacement which *does*. If you prefer python 3's semantics but need support in py2, you probably want https://github.com/ryanhiebert/backports.csv

unicodecsv

The unicodecsv is a drop-in replacement for Python 2.7's csv module which supports unicode strings without a hassle. Supported versions are python 2.6, 2.7, 3.3, 3.4, 3.5, and pypy 2.4.0.

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 as csv
>>> from io import BytesIO
>>> f = BytesIO()
>>> w = csv.writer(f, encoding='utf-8')
>>> _ = w.writerow((u'é', u'ñ'))
>>> _ = f.seek(0)
>>> r = csv.reader(f, encoding='utf-8')
>>> next(r) == [u'é', u'ñ']
True

Note that unicodecsv expects a bytestream, not unicode -- so there's no need to use codecs.open or similar wrappers. Plain open(..., 'rb') will do.

(Version 0.14.0 dropped support for python 2.6, but 0.14.1 added it back. See c0b7655248c4249 for the mistaken, breaking change.)

More Repositories

1

google-refine

A mirror for google-refine, neé Freebase Gridworks
Python
15
star
2

canto-js

A git mirror of svn-hosted canto-js (An Improved HTML5 Canvas API)
JavaScript
11
star
3

django-template-help

Makes writing template tags easier and makes communication between template authors and django developers a bit easier.
Python
5
star
4

concurrent

Some code developed as part of the Python Concurrency Workshop
4
star
5

pyechonest

Git mirror of pyechonest (Python wrapper to the Echo Nest Web API)
Python
3
star
6

duplo

A collection of utilities to make testing easier, starting with a test double management system.
Python
3
star
7

lofgren-cfaa

A repo to show the existing 18 USC Sec. 1030 ( CFAA: http://en.wikipedia.org/wiki/Computer_Fraud_and_Abuse_Act )
3
star
8

dvcs-resume

Serves a page showing contributions by the requested author
Python
3
star
9

Examples

Example Projects for Android Developer Day
Java
3
star
10

django-dev-dashboard

Django Development Dashboard
Python
2
star
11

chomp3

data: audio
Python
2
star
12

khanacademy

The mission of the Khan Academy is to provide a world-class education, for free, to anyone in the world. This repo is a GitHub mirror of the svn repo at http://code.google.com/p/khanacademy/
JavaScript
2
star
13

node_postgres

libpg binding to node
C++
1
star
14

django-quickstart

Some tools to help you get started faster with Django
1
star
15

github-contest-2009

Python
1
star
16

dbinetti.github.com

1
star
17

httpwonka

1
star
18

southfuzz

south uses depends_on for dependencies, but a missing dependency isn't obvious. I'm building a command to fix that. This repository is a test case.
Python
1
star
19

django-community

Django's Community Section
Python
1
star
20

python-cloudservers

Python bindings to Rackspace's Cloud Servers API
Python
1
star
21

nasuta

Data structures you've wished were in the language
Python
1
star
22

dotfiles

Vim Script
1
star
23

python-cloudfiles

Python language bindings for Cloud Files API
Python
1
star
24

django-patches.com

This code powers http://django-patches.com, a site that attempts to automate lots of django's patch triage process
Python
1
star