file read, binary or text mode

Ralf Schmitt ralf at
Fri Sep 24 21:24:04 CEST 2004

"Terry Reedy" <tjreedy at> writes:

> Newbies, ignore this confusion.
> 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:

$ cat
open("b.txt", "w").write("bla\x1a")
print len(open("b.txt", "rb").read())
open("b.txt", "a+")
print len(open("b.txt", "rb").read())

ralf at CRACK ~
$ python

The last character gets stripped if it's 0x1a when opening a file for
appending in text mode. I remember this from a posting on the metakit
mailing list. The poor guy corrupted his databases while he wanted to
check for write access:

- Ralf

brainbot technologies ag
boppstrasse 64 . 55118 mainz . germany
fon +49 6131 211639-1 . fax +49 6131 211639-2  mailto:ralf at

More information about the Python-list mailing list