为什么python unpack float从2.7.3到2.7.11的行为不同

时间:2016-05-16 21:09:15

标签: python-2.7

我不明白为什么以下代码在2.7.3 vs 2.7.11上给出了不同的结果,不幸的是我现在陷入了2.7.3的生产环境。

import struct

test = bytearray.fromhex("00804042")

#I get an error
#TypeError: unpack_from() argument 1 must be string or read-only buffer, not bytearray 
#so I use buffer
result = struct.unpack_from('f', buffer(test), 0)

print result

在2.7.11中我得到48.125,在2.7.3中我得到1.1777e-38。同样在2.7.3中它不接受bytearray,因此缓冲(测试)行。

0 个答案:

没有答案