Home > Q&A > body text
例如
a=b'\x58\x01' print(a)
结果:
b'X\x01'
我想打印
b'\x58\x01'
怎么格式化输出?
黄舟2017-04-18 10:28:57
''.join(map(lambda x:('/x' if len(hex(x))>=4 else '/x0')+hex(x)[2:],a))
高洛峰2017-04-18 10:28:57
def trans(s): return "b'%s'" % ''.join('\\x%.2x' % x for x in s) print(trans(b'\x58\x01'))