Marc-Andre Lemburg added the comment:

Pointing people to io.open() as alternative to codecs.open() is a good idea, 
but that doesn't make codecs.open() less useful.

The reason why codecs.open() uses binary mode is to avoid issues with automatic 
newline conversion getting in the way of the file's encoding. Think of e.g. 
UTF-16 encoded files that use newlines.

Note that codecs allow handling newlines on a line-by-line bases via the 
.readline() keepends parameter, so issues with Windows vs. Unix can be worked 
around explicitly. Since default is to keep line ends, no data loss occurs and 
application code can deal with line ends as it sees fit.

As it stands, I'm -1 on this patch, but would be +1 on mentioning io.open() as 
alternative to codecs.open() with a slightly different approach to line ends.

I don't think it's useful to tell people:
* use codecs.open() on Python 2.4, 2.5, 2.6
* use io.open() on Python 2.7 (io is too slow on 2.6 to be a real alternative 
to codecs.open())
* use open() on Python 3.4+

codecs.open() works the same across all these Python versions.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22128>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to