First, you should consider reading the documentation of
struct.unpack_from and struct.pack_into at
http://docs.python.org/library/struct.html quite carefully. It says,
that these commands take a parameter called offset, which names the
location of the data in a buffer (e.g. an opened file).
exampl
On Sat, Oct 6, 2012 at 11:26 PM, Grant Edwards wrote:
> On 2012-10-06, Dennis Lee Bieber wrote:
>> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira
>> declaimed the following in gmane.comp.python.general:
>>
>>>
>>> #WRITE
>>> fb=open('testOUT.bin')
>>
>> Unless you specify otherwise, ope
On 2012-10-06, Dennis Lee Bieber wrote:
> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira
> 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
palmeira wrote:
> Dear pythonists,
>
> I'm having a problem with read/write binary in python.
> I have a binary file that I need to read information, extract a array,
> modify this array and put these values into file again in same binary
> format.
> I need to use unpack_from and pack_into becaus
On Sat, Oct 6, 2012 at 1:27 PM, palmeira wrote:
> import struct
> bloco='>%df' %(252) #Binary format
>
> # READ
> fa=open('testIN.bin')
> my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4])# my_aray = 252
> elements array
> ## This read is OK!
>
> #WRITE
> fb=open('testOUT.bin')
> test=st
palmeira於 2012年10月6日星期六UTC+8上午11時27分47秒寫道:
> Dear pythonists,
>
>
>
> I'm having a problem with read/write binary in python.
>
> I have a binary file that I need to read information, extract a array,
>
> modify this array and put these values into file again in same binary
>
> format.
>
> I
Dear pythonists,
I'm having a problem with read/write binary in python.
I have a binary file that I need to read information, extract a array,
modify this array and put these values into file again in same binary
format.
I need to use unpack_from and pack_into because sometimes gonna need
read/wri