Conversion of perl unpack code to python - something odd

Andrew Robert andrew.arobert at gmail.com
Thu May 18 16:43:21 EDT 2006


Peter Otten wrote:
> Andrew Robert wrote:
> 
>> format='4s 4s 48s 48s 64s 4s 256s 128s 128s 48s'
> 
> You are trying to squeeze 10 items into just
> 
>> d1,d2=struct.unpack(format,data)
> 
> two variables (d1 and d2)
> 
>> ValueError: too many values to unpack
> 
> and Python is quite explicit that it doesn't like that once you realize that
> 'unpack' doesn't refer to struct.unpack() but to tuple unpacking like
> 
>>>> a, b = "ab"
>>>> a, b = "abc"
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ValueError: too many values to unpack
> 
> 
> Peter 
> 
Now I feel like a first class idiot.

Thanks for the help.

Added the extra eight variables and things worked perfectly.

Going to go stand in the corner for an hour now :)




More information about the Python-list mailing list