我使用 Windows 7,python 2.7。我想將字符串格式化為十六進制。例如,如果string = '123456 我必須轉(zhuǎn)換為\x12\x34\x56我試過這個但失敗了:string = '123456'b'\x%s\x%s\x%s' % string[0:2], string[2:4], string[4:6]
1 回答

慕森卡
TA貢獻1806條經(jīng)驗 獲得超8個贊
您可以使用以下bytearray.fromhex()方法:
>>> bytearray.fromhex('123456')
bytearray(b'\x124V') # which is the same as b'\x12\x34\x56'
添加回答
舉報
0/150
提交
取消