Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michiel Overtoom Newsgroups: comp.lang.python Subject: Re: using binary in python Date: Mon, 9 Nov 2015 11:40:20 +0100 Lines: 17 Message-ID: References: <20151108212706.GA29701@z-sverige.nu> Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de s9NbA2JmCVdt1JhwAazXBQL1qtvama1FEWgkDKz1IdWg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.05; 'open()': 0.09; 'subject:using': 0.09; 'python': 0.10; 'assume': 0.11; 'files.': 0.13; 'subject:python': 0.14; "'b'": 0.16; 'binary.': 0.16; 'from:addr:xs4all.nl': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'received:xs4all.nl': 0.16; 'wrote:': 0.16; 'string': 0.17; 'module,': 0.18; 'file.': 0.22; 'header:In- Reply-To:1': 0.24; 'values': 0.28; 'windows,': 0.29; 'convert': 0.29; 'to:name:python-list': 0.30; 'call,': 0.33; 'lets': 0.33; 'text': 0.35; 'nov': 0.35; 'mode': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'forget': 0.60; 'header:Message-Id:1': 0.61; 'greetings,': 0.61; 'received:194': 0.61; 'received:nl': 0.72; 'kent': 0.84 In-Reply-To: <20151108212706.GA29701@z-sverige.nu> X-Mailer: Apple Mail (2.2104) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98509 > On 08 Nov 2015, at 22:27, kent nyberg wrote: >=20 > 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,