P
Peter Otten
Ping said:I am writing a small program to decode MS bitmap image. When I use
statements as follow, it works fine:
header['sig'] = str(struct.unpack('2s', self.__read(src, 2))[0])
header['len'] = int(struct.unpack('1i', self.__read(src, 4))[0])
However, when I tried to rewrite them in short:
header = struct.unpack('2s1i', self.__read(src, 6))
The Python interpreter in my Linux box came up with an error:
...
header = struct.unpack('2s1i', self.__read(src, 6))
File "/usr/lib/python2.5/struct.py", line 87, in unpack
return o.unpack(s)
struct.error: unpack requires a string argument of length 8
It was weired that the required argument length increased to 8. Any idea
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/struct.py", line 87, in unpack
return o.unpack(s)
struct.error: unpack requires a string argument of length 8
('12', 909456435)
See the second table on http://docs.python.org/lib/module-struct.html for
the options you have.
Peter