[Python-Dev] Re: [Python-checkins] python/dist/src/Doc/lib libcsv.tex, 1.18, 1.19

Walter Dörwald walter at livinglogic.de
Fri Mar 18 20:10:39 CET 2005


montanaro at users.sourceforge.net wrote:
> Update of /cvsroot/python/python/dist/src/Doc/lib
> In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22325
> 
> Modified Files:
> 	libcsv.tex 
> Log Message:
> add UnicodeReader and UnicodeWriter example classes
> 
> [....]
> +The \module{csv} module doesn't directly support reading and writing
> +Unicode, but it is 8-bit clean save for some problems with \ASCII{} NUL
> +characters, so you can write classes that handle the encoding and decoding
> +for you as long as you avoid encodings like utf-16 that use NULs.

The problem is more the fact that UTF-16 would require a stateful codec.

For the UnicodeWriter IMHO the best solution would be to make the csv 
module unicode transparent (i.e. it simply calls the write method of the 
underlying stream). Then it should be possible to stack the streams like 
this:

import csv, codecs

w = cvs.writer(codecs.getwriter("utf-16")(open("foo.csv", "wb"))
w.writerow([u"foo", u"bar")]

If csv was implemented in Python this would be trivial.

Bye,
    Walter Dörwald


More information about the Python-Dev mailing list