Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'binary': 0.05; 'modify': 0.05; 'subject:skip:s 10': 0.05; 'python': 0.09; 'archive': 0.11; '252': 0.16; 'context:': 0.16; 'gonna': 0.16; 'ok!': 0.16; 'file.': 0.20; 'import': 0.21; 'struct': 0.22; 'elements': 0.23; 'values': 0.26; 'array': 0.29; "i'm": 0.29; 'error': 0.30; 'url:python': 0.32; 'file': 0.32; 'extract': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'sometimes': 0.35; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'received:216': 0.62; 'information,': 0.63; 'skip:m 50': 0.65; 'url:6': 0.65; 'dear': 0.66; 'middle': 0.66; 'subject:write': 0.84 Date: Fri, 5 Oct 2012 20:27:36 -0700 (PDT) From: palmeira To: python-list@python.org Subject: write binary with struct.pack_into MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349494066 news.xs4all.nl 6890 [2001:888:2000:d::a6]:43831 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30862 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.