using binary in python

Michiel Overtoom motoom at xs4all.nl
Mon Nov 9 05:40:20 EST 2015


> On 08 Nov 2015, at 22:27, kent nyberg <kent at z-sverige.nu> wrote:
> 
> Well, lets assume I want to write and read binary.  How is it done?

With the functions 'open()' and 'read()' and 'write()'. 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.

You also might want to look into the 'struct' module, functions 'pack()' and 'unpack()'. They convert python values to their binary representation which is used in binary files.

Greetings,






More information about the Python-list mailing list