How to decode a Unicode string in Python 3?

I have unicode-like strings, but with a slash. For example, '\\u000D' . I need to decode them like regular strings. The above example should be converted to '\r' , which corresponds to '\u000D' .

+6
source share
1 answer

Use the unicode-escape codec.

 >>> import codecs >>> codecs.decode('\\u000D', 'unicode-escape') '\r' 
+10
source

Source: https://habr.com/ru/post/1013769/


All Articles