file read, binary or text mode

Alan G Isaac aisaac at
Sun Sep 26 03:24:35 CEST 2004

"Roel Schroeven" <rschroev_nospam_ml at> wrote in message
news:OjW4d.255917$OR1.13371520 at
> It's safe in the sense that everything goes out exactly as it came in.
> For example, gzip uses binary mode even when compressing text files. The
> files may be text, but gzip doesn't care about that. It doesn't care
> about words, sentences and line endings, but it does care about
> representing exactly the bytes that are in the file.

I think the following is the same question from another angle.
I have an .zip archive of compressed files that
I want to decompress.  Using the zipfile module,
I tried
for zname in z.namelist():

The original files were all plain text,
created on an unspecified platform.
The files I decompressed this way contained
*two successive* carriage returns
(ASCII 13) at the end of each line.
If I change 'w' to 'wb' I get only one
carriage return at the end of each line.

Why is this extra carriage return added?
My original guess was the using 'w' instead
of 'wb' would be the right action, since the
platform for the original files is unspecified
and the original files are known to be plain text.

Alan Isaac

More information about the Python-list mailing list