Reading binary data

Aaron "Castironpi" Brady castironpi at
Wed Sep 10 21:26:42 CEST 2008

On Sep 10, 1:12 pm, Aaron Scott <aaron.hildebra... at> wrote:
> Sorry, I had posted the wrong error. The error I am getting is:
>      struct.error: unpack requires a string argument of length 12
> which doesn't make sense to me, since I'm specifically asking for 11.
> Just for kicks, if I change the line to
>      print struct.unpack('3sII',
> I get the result
>      ('GDE', 33554432, 16777216)
> ... which isn't even close, past the first three characters.

Sometimes 'endian' order can cause this.  Try '<3sII' and '>3sII' for
your formats to differentiate.

Also, if your file is not packed the way that 'struct' expects, you
might need to read the string and integers separately.


>>> struct.Struct( '3s' ).size + struct.Struct( 'II' ).size
>>> struct.Struct( '3sII' ).size

More information about the Python-list mailing list