Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: jmp Newsgroups: comp.lang.python Subject: Re: Writing a stream of bytes Date: Fri, 15 Jan 2016 17:23:58 +0100 Lines: 29 Message-ID: References: <20160115100830.78e4b731@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 5sDyTN5Hi1OMvZHWkHDYpwQupzecW2EhOTcCtCGT1e+Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'format:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Writing': 0.09; '-tkc': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'bytes': 0.18; 'file:': 0.22; 'struct': 0.22; 'import': 0.24; 'tim': 0.24; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'chase': 0.29; 'clicked': 0.29; 'grouping': 0.29; 'problem': 0.33; 'could': 0.35; '(and': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'thank': 0.38; 'end': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'received:194': 0.61; 'charset:windows-1252': 0.62; 'great': 0.63; 'canonical': 0.91; 'lap': 0.91; 'resides': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: paris.sequans.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: <20160115100830.78e4b731@bigbox.christie.dr> 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:101763 On 01/15/2016 05:08 PM, Tim Chase wrote: > [sorry, toddler on my lap clicked before I could type] > >> import struct >> with open('toto', 'wb') as f: f.write(struct.pack('<4B', *[1,2,3,4])) > > This one does what you want. The problem resides in your check: > >> I always end up with the following bytes on file: >> !hexdump toto >> 0000000 0201 0403 > > Hexdump is grouping them. Try the canonical format: > > !hexdump -C toto > 00000000 01 02 03 04 |....| > 00000004 > > > -tkc Great ! thank you, (and Bartc). jm