- 論壇徽章:
- 0
|
有個網(wǎng)絡(luò)數(shù)據(jù)包要解包,本來以為這樣兩句話可以搞定
for data in fileListData:
print len(data)
formatstr=(len(data)/50)*"33scII8s"
templist=struct.unpack(formatstr,data)
可是它提示格式化字符串和數(shù)據(jù)長度不匹配,最后化成這樣寫才通過了,我看不出來這是什么區(qū)別?
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]))
數(shù)據(jù)我保證都是50的倍數(shù)長,抓包檢驗過的。 |
|