2024-05-16 08:29:35 发布
网友
我使用Windows7,Python2.7
我想把字符串格式化成十六进制。 e、 例如,如果string = '123456 我必须转换成\x12\x34\x56
string = '123456
\x12\x34\x56
我尝试过这个,但失败了:
string = '123456' b'\x%s\x%s\x%s' % string[0:2], string[2:4], string[4:6]
您可以使用bytearray.fromhex()方法:
bytearray.fromhex()
>>> bytearray.fromhex('123456') bytearray(b'\x124V') # which is the same as b'\x12\x34\x56'
您可以使用
bytearray.fromhex()
方法:相关问题 更多 >
编程相关推荐