471,873 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

struct unpack issue

Hash: SHA1


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.


- --
Ping Zhao, PhD Student Dormitory: +82-(0)31-338-9503-0415
Information Engineering io******@gmail.com
Myongji University http://oceanio.wordpress.com
GMT +09:00 (Seoul)

Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkhTHocACgkQyOZNd2jjOpvTxgCfYnJKZqf4d3 Em3xKDcAcpvK8i
Jun 27 '08 #1
0 1456

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Josiah Carlson | last post: by
5 posts views Thread by grant | last post: by
10 posts views Thread by Giovanni Bajo | last post: by
3 posts views Thread by David Bear | last post: by
4 posts views Thread by OhKyu Yoon | last post: by
2 posts views Thread by brnstrmrs | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.