jdunck / python-unicodecsv

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
Other
594 stars 87 forks source link

How can I write code that work in Python 2 and 3? #57

Closed ryanhiebert closed 9 years ago

ryanhiebert commented 9 years ago

unicodecsv's API differs whether you're on Python 2 or 3, because on Python 3 it delegates to the stdlib. Unfortunately, even ignoring the use of cStringIO, the README example doesn't work in Python 3, because there's no encoding argument to reader (or writer), since the Python 3 csv module just writes strings (unicode).

I'm not sure what the best path forward is to write code that works on both Python 2 and 3. Perhaps it's to write a wrapper that gives an API that works on both. I'm not yet sure. Ideas welcome.