Re: Writing a stream of bytes

2016-01-15 Thread Gregory Ewing
Mark Lawrence wrote: On 15/01/2016 15:55, jmp wrote: Hi pyple ! In the UK it's "purple", a bit like "color" is wrong, it's "colour". Now, let's not make fun of people with English as a second language. That was obviously written with a Jäger accent: http://girlgenius.wikia.com/wiki/J%C3%A4

Re: Writing a stream of bytes

2016-01-15 Thread Peter Otten
Mark Lawrence wrote: > On 15/01/2016 15:55, jmp wrote: >> Hi pyple ! > > In the UK it's "purple", a bit like "color" is wrong, it's "colour". Yeah, you Brits are a deep purple. (I thought I had already exhausted my allowance for lame jokes yesterday. Seems I was wrong ;) -- https://mail.pyth

Re: Writing a stream of bytes

2016-01-15 Thread Mark Lawrence
On 15/01/2016 15:55, jmp wrote: Hi pyple ! In the UK it's "purple", a bit like "color" is wrong, it's "colour". I'd like to write a stream of bytes into a file. I'd like to use the struct (instead of bytearray) module because I will have to write more than bytes. If you'd like to clarify

Re: Writing a stream of bytes

2016-01-15 Thread jmp
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 f

Re: Writing a stream of bytes

2016-01-15 Thread Tim Chase
[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 > 000 0201 0403

Re: Writing a stream of bytes

2016-01-15 Thread Tim Chase
On 2016-01-15 16:55, jmp wrote: > Hi pyple ! > > > I'd like to write a stream of bytes into a file. I'd like to use > the struct (instead of bytearray) module because I will have to > write more than bytes. > > let's say I want a file with 4 bytes in that order: > > 01 02 03 04 > > None of the

Re: Writing a stream of bytes

2016-01-15 Thread BartC
On 15/01/2016 15:55, jmp wrote: Hi pyple ! I'd like to write a stream of bytes into a file. I'd like to use the struct (instead of bytearray) module because I will have to write more than bytes. let's say I want a file with 4 bytes in that order: 01 02 03 04 None of these work: import struc

Writing a stream of bytes

2016-01-15 Thread jmp
Hi pyple ! I'd like to write a stream of bytes into a file. I'd like to use the struct (instead of bytearray) module because I will have to write more than bytes. let's say I want a file with 4 bytes in that order: 01 02 03 04 None of these work: import struct with open('toto', 'wb') as