- 论坛徽章:
- 0
|
有个网络数据包要解包,本来以为这样两句话可以搞定
for data in fileListData:
print len(data)
formatstr=(len(data)/50)*"33scII8s"
templist=struct.unpack(formatstr,data)
可是它提示格式化字符串和数据长度不匹配,最后化成这样写才通过了,我看不出来这是什么区别?
for data in fileListData:
print len(data)
formatstr=(len(data)/50)*"50s"
templist=struct.unpack(formatstr,data)
formatstr="33sc16s"
formatstr2="II8s"
for i in templist:
#print i
temp2=struct.unpack(formatstr,i)
temp3=struct.unpack(formatstr2,temp2[2])
self.ncfileInfo.append((temp2[0],temp2[1],temp3[1],temp3[0]))
数据我保证都是50的倍数长,抓包检验过的。 |
|