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


Groups > comp.lang.python > #30865

Re: write binary with struct.pack_into

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dihedral88888@googlemail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'received:209.85.223': 0.03; 'binary': 0.05; 'modify': 0.05; 'subject:skip:s 10': 0.05; 'python': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'archive': 0.11; '252': 0.16; 'context:': 0.16; 'gonna': 0.16; 'ok!': 0.16; 'file.': 0.20; 'import': 0.21; 'struct': 0.22; 'cc:2**0': 0.23; 'elements': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'values': 0.26; 'oop': 0.29; 'pickle': 0.29; 'array': 0.29; "i'm": 0.29; 'error': 0.30; 'url:python': 0.32; 'file': 0.32; 'computing': 0.32; 'extract': 0.33; 'problem': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'from:addr:googlemail.com': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'subject:with': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'different': 0.63; 'information,': 0.63; 'skip:m 50': 0.65; 'url:6': 0.65; 'dear': 0.66; 'middle': 0.66; 'heavy': 0.83; 'subject:write': 0.84; '8bit%:70': 0.91
Newsgroups comp.lang.python
Date Fri, 5 Oct 2012 21:39:09 -0700 (PDT)
In-Reply-To <mailman.1889.1349494066.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw
References <mailman.1889.1349494066.27098.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 123.192.32.215
MIME-Version 1.0
Subject Re: write binary with struct.pack_into
From 88888 Dihedral <dihedral88888@googlemail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.1890.1349498359.27098.python-list@python.org> (permalink)
Lines 86
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349498359 news.xs4all.nl 6971 [2001:888:2000:d::a6]:50603
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30865

Show key headers only | View raw


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 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.

Are you writing and reading files produce by different 
languages?

The pickle part  is better  for OOP and glue logics in python.

The heavy computing part should be done in CYTHON.

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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