[I18n-sig] codecs module, readlines and xreadlines

M.-A. Lemburg mal@lemburg.com
Fri, 17 Jan 2003 10:04:57 +0100


Martin v. L=F6wis wrote:
> Guido van Rossum <guido@python.org> writes:
>=20
>>That's exactly what Universal newlines does.  Have I missed something?
>=20
> The issue is whether codecs.open should follow the platform
> conventions for text mode if neither "b" nor "U" is passed. Builtin
> open currently does, codecs.open does not (instead, it treats a plain
> "r" just as if "rb" had been passed).

I'd say: let the codecs decide what to do here. After all, codecs.open()
only provide an interface to the codecs and leaves all the processing to
them. If a codec thinks that line ends should all be converted to '\n'
then so be it. That's also why codecs.open() appends an 'b' to the
mode in case it is not already there: otherwise opening files in e.g.
UTF-16 on Windows would lose big.

I think that the codecs.open() kind of treatment is more reliable
than the open() one for text files. Simply because you always know
what will happen and can then apply whatever conversion needs
to be done in the program.

> Furthermore, the *implementation* of universal newlines is useless for
> codecs.open, as the newline conversion must happen after decoding, not
> before.

Right.

--=20
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/