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


Groups > comp.lang.python > #30890

Re: write binary with struct.pack_into

References <1349494056881-4991234.post@n6.nabble.com> <mailman.1891.1349499136.27098.python-list@python.org> <k4pbik$6qf$1@reader1.panix.com>
Date 2012-10-06 23:52 +1000
Subject Re: write binary with struct.pack_into
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1902.1349531571.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

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

csiph-web