codecs, csv issues

John Machin sjmachin at lexicon.net
Fri Aug 22 18:22:26 EDT 2008


On Aug 22, 11:52 pm, George Sakkis <george.sak... at gmail.com> wrote:
> I'm trying to use codecs.open() 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 = codecs.open('tmp.txt', 'w', encoding='utf8')
>     s = u'\u0391\u03b8\u03ae\u03bd\u03b1'
>     print >> f, s
>     print >> f, s
>     f.close()

This is documented behaviour:
"""
Note
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