struct.error: unpack requires a string argument of length 4

Posted by Thomas O on Stack Overflow See other posts from Stack Overflow or by Thomas O
Published on 2010-04-10T01:12:20Z Indexed on 2010/04/10 1:13 UTC
Read the original article Hit count: 426

Filed under:
|

Python says I need 4 bytes for a format code of "BH":

struct.error: unpack requires a string argument of length 4

Here is the code, I am putting in 3 bytes as I think is needed:

major, minor = struct.unpack("BH", self.fp.read(3))

"B" = Unsigned char (1 byte) + "H" unsigned short (2 bytes) = 3 bytes (!?)

struct.calcsize("BH") says 4 bytes.

© Stack Overflow or respective owner

Related posts about python

Related posts about struct