Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: write binary with struct.pack_into (http://www.velocityreviews.com/forums/t953105-re-write-binary-with-struct-pack_into.html)

Dennis Lee Bieber 10-06-2012 04:52 AM

Re: write binary with struct.pack_into
 
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/


Grant Edwards 10-06-2012 01:26 PM

Re: write binary with struct.pack_into
 
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

Chris Angelico 10-06-2012 01:52 PM

Re: write binary with struct.pack_into
 
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


All times are GMT. The time now is 12:33 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.