+ 10

How to convert a raw string into a normal string in Python?

I want to convert a raw string into a normal string. In the attached example https://code.sololearn.com/cOzEyLaN6gok/?ref=app I do this with the exec()-function in section #4. Could anybody please tell me a more elegant or alternative way to do this instead of doing this with exec()?

24th Dec 2019, 7:01 AM
Jan Markus
5 Answers
+ 3
Try to decode using 'unicode-escape'. d = c.encode().decode('unicode-escape')
24th Dec 2019, 8:14 AM
Théophile
Théophile - avatar
+ 5
Théophile That is the solution which I was searching for. molang On the website you mentioned I had searched before posting this question and I did not find a suitable answer to my question. Thank you Theophile, molang and Lothar for your answers!
24th Dec 2019, 10:31 AM
Jan Markus
+ 2
Lothar No, that does not help.
24th Dec 2019, 7:18 AM
Jan Markus
24th Dec 2019, 8:18 AM
molang
molang - avatar