Timothy Crone  <tjcr...@gmail.com> wrote:
>header = "s"
>data = list(unpack(header,f.read(1)))
>
>however this:
>
>header = "si"
>data = list(unpack(header,f.read(5)))
>
>throws
>
>struct.error: unpack requires a string argument of length 8
>
>So unpack expects 7 additional bytes when an integer is added to the
>format string. Does anyone know what is going on?

It's adding pad bytes so that the format matches the equivilent C
structure on your machine.  You should use either the "<" little-endian
or the ">" big-endian prefix depending on the byte order used in the file
you're trying to unpack.  You can also use the "=" native byte-order
flag if endianness of the file format changes according to the machine
your Python program runs on.  If you use any of these flags, no extra
padding will be inserted.

                                Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  rri...@csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to