Reading binary data

Wojtek Walczak gminick at bzt.bzt
Wed Sep 10 19:51:58 CEST 2008


On Wed, 10 Sep 2008 10:43:31 -0700 (PDT), Aaron Scott wrote:
>> signature, version, attr_count = struct.unpack('3cII',
>> yourfile.read(11))
>>
>
> This line is giving me an error:
>
> Traceback (most recent call last):
>   File "test.py", line 19, in <module>
>     signature, version, attr_count = struct.unpack('3cII',
> file.read(12))
> ValueError: too many values to unpack

Do:
print struct.unpack('3cII', yourfile.read(11))
instead of:
signature, version, attr_count = struct.unpack('3cII', yourfile.read(11))
to check what does struct.unpack return.

I guess it returns more than three elements. Just like below:

>>> a,b,c=(1,2,3,4)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: too many values to unpack

As you can see the fourth element from the tuple has no place to go.
Same thing happens in your code.

HTH.

-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/



More information about the Python-list mailing list