Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python unpack problem

Tags:

python

I have:

a, b, c, d, e, f[50], g = unpack('BBBBH50cH', data)

The problem is

f[50] (too many values to unpack)

How do I do what I want?

like image 430
Jonathan Avatar asked Mar 11 '11 15:03

Jonathan


1 Answers

I think by f[50] you are trying to denote "a list of 50 elements"?

In Python 3.x you can do a, b, c, d, e, *f, g to indicate that you want f to contain all the values that don't fit anywhere else (see this PEP).

In Python 2.x, you will need to write it out explicitly:

x = unpack(...)
a, b, c, d, e = x[:5]
f = x[5:55]
<etc>
like image 165
Katriel Avatar answered Oct 27 '22 09:10

Katriel