无法从字节转换为int

2024-04-19 08:42:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下一个价值

value = bytearray(b'\x85\x13\xbd|\xfb\xbc\xc3\x95\xbeL6L\xfa\xbf0U_`$]\xca\xee]z\xef\xa0\xd6(\x15\x8b\xca\x0e\x1f7\xa9\xf0\xa4\x98\xc5\xdf\xcdM5\xef\xc2\x052`\xeb\x13\xd9\x99B.\x95\xb2\xbd\x96\xd9\x14\xe6F\x9e\xfd\xd8\x00')

当我尝试在python3.x中转换时,效果很好。

>>> int.from_bytes(value, byteorder='little')
2909369579440607969688280064437289348250138784421305732473112318543540722321676649649580720015118044118243611774710427666475769804427735898727217762490192773

如何在python2.7中转换它?我已经读过convert a string of bytes into an int (python)

struct.unpack(fmt, value)[0]

但不知道怎么处理fmt。


Tags: bytesvalueint价值xfbxbdfmtbytearray