I have a variable x which has value '\202', I want to convert x into raw_x = '\\202'. I have tried couple of things below, but didn't get desired output.
x = '\202' #we cannot modify x = r'\202', because x is coming from other source
print(x)
raw_x = fr"{x}"
print(raw_x)
raw_x = r"{}".format(x)
print(raw_x)
raw_x = "%r" %x
print(raw_x)
raw_x = x.encode("unicode_escape").decode()
print(raw_x)
# Desire raw_x = r'\202' or raw_x = '\\202'
print("Desired raw_x output: \\202")
Console Output:
'\x82'
\x82
Desired raw_x output: `\202`