Python unpack problem
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?
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>
The problem is with the 50c
part of the unpack. This is reading 50 characters from the buffer, and returning this as 50 seperate values. If you change it to
a, b, c, d, e, f, g = unpack('BBBBH50sH', data)
f
will be a list of 50 characters read from the buffer, which is what I suspect you want.
精彩评论