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


Groups > comp.lang.python > #30862

write binary with struct.pack_into

Date 2012-10-05 20:27 -0700
From palmeira <palmeira@gmail.com>
Subject write binary with struct.pack_into
Newsgroups comp.lang.python
Message-ID <mailman.1889.1349494066.27098.python-list@python.org> (permalink)

Show all headers | View raw


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/write in the middle of file.

Script:

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=struct.pack_into(bloco,fb.write()[0*4:251*4])  # ERROR in this WRITE




Regards,

Ronaldo Palmeira.




--
View this message in context: http://python.6.n6.nabble.com/write-binary-with-struct-pack-into-tp4991234.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Thread

write binary with struct.pack_into palmeira <palmeira@gmail.com> - 2012-10-05 20:27 -0700
  Re: write binary with struct.pack_into 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-05 21:39 -0700
  Re: write binary with struct.pack_into 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-05 21:39 -0700
  Re: write binary with struct.pack_into Alexander Blinne <news@blinne.net> - 2012-10-06 17:55 +0200

csiph-web