-1
我正面臨以下錯誤。Python中的字符串打包解包
Traceback (most recent call last):
File "Thread_main.py", line 681, in <module>
fdata = struct.unpack('f', str(AObytes[i:i+3]))
struct.error: unpack requires a string argument of length 4
這裏是錯誤的代碼行。
for i in range(640,8196,4):
### === This AO bytes mapping is till for all AOS data , Last bytes are 8192,8193,8194,8195
fdata = struct.unpack('f', str(AObytes[i:i+4]))
AOSID[aop1] = fdata[0]
aop1 =aop1+1
我已經在頂部定義了Aobytes。 AObytes = [0]*8200
你給出的兩個例子是不同的。在第一個中,你得到的長度爲3的AObytes。第二個長度爲4的片。第二個應該工作,只要你正確縮進代碼。錯誤消息清楚地說明了問題所在。解開浮點數需要4個字符(字節)。 – user1514631