question on using format in struct module

Steve Holden sholden at holdenweb.com
Wed Oct 24 20:32:02 EDT 2001


"Suresh" <mj_dup at yahoo.com> wrote ...
> Hi All,
>
> I need some help with struct module. I have a binary file (obtained
> with our product) and it contains char, int, float values. I used
> struct module for this purpose in this manner --
>
> import struct
> binfile = open('binary_file.bin','rb')
> format = ????
> bytes = struct.calcsize(format)
> i1, i2 and so on = struct.unpack(format, binfile.read(bytes))
>
> (i1, i2, i3 etc will have the equivalent text values of the binary
> fields from the "binary_file.bin")
>
> The problem is specifying for "format" variable. Since my binary file
> has non-uniform and different data types how do I specify for format =
> ???? Is there a way I can tell python to decide upon format looking at
> the binary file. Any help is appreciated !
>
So, what you are sayng is that you don't know the format of the tile, and
you'd like someone to tell you how to decode it? If *you* don't know how to
decode your application's data, how do you expect someone else to? I must be
missing something.

Maybe there's something you can use in

    http://www.holdenweb.com/Python/PDCode/dbxread.py

which reads binary files from Outlokk Express.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list