struct unpack issue
Ping Zhao
ioceanio at gmail.com
Fri Jun 13 21:27:34 EDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
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 on this? I am using a 32bit pentium-m and the picture file was stored in little-edian format.
Sincerely,
- --
Ping Zhao, PhD Student Dormitory: +82-(0)31-338-9503-0415
Information Engineering ioceanio at gmail.com
Myongji University http://oceanio.wordpress.com
GMT +09:00 (Seoul)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkhTHocACgkQyOZNd2jjOpvTxgCfYnJKZqf4d3Em3xKDcAcpvK8i
tx4AoI0WvEBv5tvoTQrQlMsj/3UO16t1
=SGnL
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list