如何在 Python 中表示字节数组(如 Java 中的 byte[])?我需要用 gevent 通过网络发送它。
byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00};
在Python 3中,我们使用bytes
对象,也称为str
在Python 2中。
# Python 3
key = bytes([0x13, 0x00, 0x00, 0x00, 0x08, 0x00])
# Python 2
key = ''.join(chr(x) for x in [0x13, 0x00, 0x00, 0x00, 0x08, 0x00])
我发现使用更方便base64
模块...
# Python 3
key = base64.b16decode(b'130000000800')
# Python 2
key = base64.b16decode('130000000800')
您还可以使用文字...
# Python 3
key = b'\x13\0\0\0\x08\0'
# Python 2
key = '\x13\0\0\0\x08\0'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)