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
  • 844
  • 1
  • 9
  • 15

1 Answers1

0

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

>>> print("\\1")
\1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Netwave
  • 40,134
  • 6
  • 50
  • 93