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


Groups > comp.lang.python > #101761 > unrolled thread

Re: Writing a stream of bytes

Started byTim Chase <python.list@tim.thechases.com>
First post2016-01-15 10:08 -0600
Last post2016-01-15 10:08 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Writing a stream of bytes Tim Chase <python.list@tim.thechases.com> - 2016-01-15 10:08 -0600

#101761 — Re: Writing a stream of bytes

FromTim Chase <python.list@tim.thechases.com>
Date2016-01-15 10:08 -0600
SubjectRe: Writing a stream of bytes
Message-ID<mailman.18.1452874677.15297.python-list@python.org>
[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


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web