file read, binary or text mode
peter at engcorp.com
Fri Sep 24 21:48:39 CEST 2004
Ralf Schmitt wrote:
> "Terry Reedy" <tjreedy at udel.edu> writes:
>>On Windows, text mode autoconverts \r\n to \n on input and viceverse on
>>output. I believe that that is all the difference. Period.
> That's not quite the case. As always windows sucks big time:
[snip example with ^Z]
> The last character gets stripped if it's 0x1a when opening a file for
> appending in text mode.
Good point. Note for the picky: it doesn't just get stripped... it
*is* the last character, even if there's data following. Or to
be blunt, ^Z (byte value 26) is treated as EOF on Windows when not
using binary mode to read files.
I suspect Terry and others (including I) overlooked this because
^Z is pretty much obsolete, and since few applications *write*
^Z as the last character of text files any more, almost nobody
bothers to remember that text mode is slightly more complicated
than just the CR LF to LF conversion and back.
More information about the Python-list