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


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

Re: write binary with struct.pack_into

Started byDennis Lee Bieber <wlfraed@ix.netcom.com>
First post2012-10-06 00:52 -0400
Last post2012-10-06 23:52 +1000
Articles 3 — 3 participants

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: write binary with struct.pack_into Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-06 00:52 -0400
    Re: write binary with struct.pack_into Grant Edwards <invalid@invalid.invalid> - 2012-10-06 13:26 +0000
      Re: write binary with struct.pack_into Chris Angelico <rosuav@gmail.com> - 2012-10-06 23:52 +1000

#30866 — Re: write binary with struct.pack_into

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-10-06 00:52 -0400
SubjectRe: write binary with struct.pack_into
Message-ID<mailman.1891.1349499136.27098.python-list@python.org>
On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira <palmeira@gmail.com>
declaimed the following in gmane.comp.python.general:

> 
> #WRITE
> fb=open('testOUT.bin')

	Unless you specify otherwise, open() defaults to read-only
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [next] | [standalone]


#30889

FromGrant Edwards <invalid@invalid.invalid>
Date2012-10-06 13:26 +0000
Message-ID<k4pbik$6qf$1@reader1.panix.com>
In reply to#30866
On 2012-10-06, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira <palmeira@gmail.com>
> declaimed the following in gmane.comp.python.general:
>
>> 
>> #WRITE
>> fb=open('testOUT.bin')
>
> 	Unless you specify otherwise, open() defaults to read-only

It also defaults to 'text' mode which does cr/lf translaction.  That
will break both reads and writes on any binary file containing 0x0a
and 0x0d bytes.

-- 
Grant

[toc] | [prev] | [next] | [standalone]


#30890

FromChris Angelico <rosuav@gmail.com>
Date2012-10-06 23:52 +1000
Message-ID<mailman.1902.1349531571.27098.python-list@python.org>
In reply to#30889
On Sat, Oct 6, 2012 at 11:26 PM, Grant Edwards <invalid@invalid.invalid> wrote:
> On 2012-10-06, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
>> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira <palmeira@gmail.com>
>> declaimed the following in gmane.comp.python.general:
>>
>>>
>>> #WRITE
>>> fb=open('testOUT.bin')
>>
>>       Unless you specify otherwise, open() defaults to read-only
>
> It also defaults to 'text' mode which does cr/lf translaction.  That
> will break both reads and writes on any binary file containing 0x0a
> and 0x0d bytes.

And, in Python 3, it'll be returning Unicode characters too, unless
the decode fails. You definitely want binary mode.

ChrisA

[toc] | [prev] | [standalone]


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


csiph-web