How to decode string with escape sequences in Python

2 Answers

0 votes
s = "Python\ninterpreted\n\"programming\""

decoded_string = bytes(s, "utf-8").decode("unicode_escape") 

print(decoded_string)




'''
run:

Python
interpreted
"programming"

'''

 



answered Apr 25, 2021 by avibootz
0 votes
import codecs

s = "Python\ninterpreted\n\"programming\""

decoded_string = codecs.decode(s, 'unicode_escape')

print(decoded_string)




'''
run:

Python
interpreted
"programming"

'''

 



answered Apr 25, 2021 by avibootz
...