我试图这样做:
struct.unpack('d', barray[:HALF_BYTES])[0]
其中barray[:HALF_BYTES]
是12字节数组
但是我收到了这个错误:
Traceback (most recent call last):
File "random_input_sample_drawer.py", line 19, in <module>
print (struct.unpack('d', barray[:HALF_BYTES])[0])
struct.error: unpack requires a bytes object of length 8
我该如何解决?
答案 0 :(得分:0)
您可以使用:
int.from_bytes(barray[:HALF_BYTES], byteorder='big', signed=False)
将这12个字节转换为整数,如果那是你想要做的,假设你的barray是一个bytearray()而你正在使用python 3.2 +