I need to print out a string of binary escape sequences, e.g. \x05\x03\x87, exactly as they appear. When I try to print them, Python returns a string of weird non-ASCII characters. How can I print them as a string literal?
I need to print out a string of binary escape sequences, e.g. \x05\x03\x87 ,
Share
reprEDIT
Sven makes the point that the OP might want every character dumped in hex, even the printable ones, in which case, the best solution I can think of is:
ADDITIONAL EDIT
Four years later, it occurs to me that this might be both faster and more readable:
or even