根据这个图,结合struct
def DispBytes(b): '''把 bytes 中相应的值转成字串后输出 t = b'\x023\x02' --> DispBytes(t) '02 33 02' ''' import struct disp = '' if type(b) == bytearray: b = bytes(b) if type(b) == bytes: tup = struct.unpack('B'*len(b),b)# 转换成元组 ls = list(tup) for i in range(len(ls)): if(i == 0): disp += '{0:02X}'.format(ls[i]) else: disp += ' {0:02X}'.format(ls[i]) return disp