question on using format in struct module

Suresh mj_dup at yahoo.com
Wed Oct 24 17:39:04 EDT 2001


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 !

thanks again,
./Suresh



More information about the Python-list mailing list