Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101763

Re: Writing a stream of bytes

From jmp <jeanmichel@sequans.com>
Newsgroups comp.lang.python
Subject Re: Writing a stream of bytes
Date 2016-01-15 17:23 +0100
Message-ID <mailman.20.1452875051.15297.python-list@python.org> (permalink)
References <n7b4os$9j2$1@ger.gmane.org> <20160115100830.78e4b731@bigbox.christie.dr>

Show all headers | View raw


On 01/15/2016 05:08 PM, Tim Chase wrote:
> [sorry, toddler on my lap clicked <send> 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




Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Writing a stream of bytes jmp <jeanmichel@sequans.com> - 2016-01-15 17:23 +0100

csiph-web