0

I have got a requirement where I need to send a string having "\1" to some other device and it expects utf-8 format. but its getting printed in a weird format as shown below

print("*/\1/p".encode("utf-8"))

output in the device enter image description here

I just want my string "\1" to print as "\1" when encoded in utf-8 format.

ahmed meraj
  • 644
  • 1
  • 7
  • 13

1 Answers1

0

You just need to escape the \ character, and not encode:

>>> print("\\1")
\1
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Netwave
  • 36,219
  • 6
  • 36
  • 71