codecs, csv issues

John Machin sjmachin at
Sat Aug 23 00:22:26 CEST 2008

On Aug 22, 11:52 pm, George Sakkis <george.sak... at> wrote:
> I'm trying to use and I see two issues when I pass
> encoding='utf8':
> 1) Newlines are hardcoded to LINEFEED (ascii 10) instead of the
> platform-specific byte(s).
>     import codecs
>     f ='tmp.txt', 'w', encoding='utf8')
>     s = u'\u0391\u03b8\u03ae\u03bd\u03b1'
>     print >> f, s
>     print >> f, s
>     f.close()

This is documented behaviour:
Files are always opened in binary mode, even if no binary mode was
specified. This is done to avoid data loss due to encodings using 8-
bit values. This means that no automatic conversion of '\n' is done on
reading and writing.

More information about the Python-list mailing list