codecs.open on Win32 -- converting my newlines to CR+LF

Chris Rebert clp2 at rebertia.com
Thu Aug 27 02:06:07 EDT 2009


On Wed, Aug 26, 2009 at 8:40 PM, Ryan McGuire<usenet at enigmacurry.com> wrote:
> On Aug 26, 11:04 pm, Philip Semanchuk <phi... at semanchuk.com> wrote:
>> Try using "rb" instead of "r" for the mode in the call to open().
>>
>> HTH
>> Philip
>
> That does indeed fix the problem, thanks! Still seems like the docs
> are wrong though.

Yeah, the need to specify "b" does seem rather incongruous:

codecs.open(filename, mode[, encoding[, errors[, buffering]]])
    [...]
    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 b'\n'
is done on reading and writing.

File a bug perhaps?: http://bugs.python.org/

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list