Python 3如何将以字节表示的大数字转换为整数?

Python 3如何将以字节表示的大数字转换为整数?,python,python-3.x,byte,Python,Python 3.x,Byte,我有: 如何将其转换回257 另外,是否有任何方法可以在不指定字节数的情况下将显示到_bytes?使用补码并再次指定字节顺序 n = 257 a = n.to_bytes(2, 'little') a = b'\x01\x01' >>> n = 257 >>> n_bytes = n.to_bytes(2, "little") >>> n_again = int.from_bytes(n_bytes, "little") >>&

我有:

如何将其转换回
257

另外,是否有任何方法可以在不指定字节数的情况下将
显示到_bytes

使用补码并再次指定字节顺序

n = 257
a = n.to_bytes(2, 'little')
a = b'\x01\x01'
>>> n = 257
>>> n_bytes = n.to_bytes(2, "little")
>>> n_again = int.from_bytes(n_bytes, "little")
>>> n_again == n
True