problem with struct module

Angelo Secchi secchi at sssup.it
Tue Feb 24 10:28:55 EST 2004


I'm trying to use the unpack method in the struct module to parse a
binary file without success. I have a binary file with records that
include many fields for a total length of 1970. Few days ago I was
suggested by the list to use the struct module to parse it using the
following code in the hypothesis that for each records I have just two
fields:

import struct
fmt='10s1960s'
size=struct.calcsize(fmt)
f=file("data")
s=f.read(size)

while s:
    print 'read:', s
    d1,d2=struct.unpack(fmt,s)
    print 'unpack', d1

Probably I was not even able to explain my problem since it seem that
this code is not able to read the file. Can anybody help me, maybe
asking for other infos they need? Also just suggest me a place where I
can find examples of using struc.unpack would be very helpful.
Thanks.
a.




--
========================================================
 Angelo Secchi                     PGP Key ID:EA280337
========================================================
  Current Position:
  Graduate Fellow Scuola Superiore S.Anna
  Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
  ph.: +39 050 883365
  email: secchi at sssup.it	www.sssup.it/~secchi/
========================================================




More information about the Python-list mailing list