using binary in python

Marko Rauhamaa marko at pacujo.net
Mon Nov 9 05:56:08 EST 2015


Michiel Overtoom <motoom at xs4all.nl>:

> If you're on Windows, don't forget to include a 'b' in the mode string
> of the open() call, otherwise Python will assume that you're opening a
> text file.

Python has brought that blessing to other operating systems, as well.

One of the principal UNIX innovations was to see files as simple byte
sequences. The operating system would place no semantics on the meaning
or structure of the bytes.

Python presents a different concept of a file; Python files are either
text files or binary files. The dichotomy is built on top of the UNIX
file system. However, the Python model "leaks" in that nothing prevents
you from opening a binary file as a text file or vice versa.


Marko



More information about the Python-list mailing list