Jul-12-2020, 05:32 AM
Looks like at least partly you have a byte string. When printed by default, if the byte maps to an ASCII character (like \x20), then it prints that character. \x20 is a space, so the 20s are removed and replaced with spaces in your printout.
If you just need the hex values, you could use (among other things) the hex method.
If you just need the hex values, you could use (among other things) the hex method.
>>> b = b'\x14\x02\x01\x00\x20\x00\x00\x00\x03\x18\x90\x42\x57\x23\x08\x00\x57\x23\x08\x00' >>> b b'\x14\x02\x01\x00 \x00\x00\x00\x03\x18\x90BW#\x08\x00W#\x08\x00' >>> b.hex() '1402010020000000031890425723080057230800'If you want the specific format, you could split it up and add the "\x" in front.
>>> h = b.hex() >>> print("".join([f"\\x{h[i:i+2]}" for i,_ in enumerate(h[::2])])) \x14\x40\x02\x20\x01\x10\x00\x02\x20\x00\x00\x00\x00\x00\x00\x00\x03\x31\x18\x89