Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode a unicode-like string in Python 3?

I have unicode-like strings but with slash escaped. For example, '\\u000D'. I need to decode them as normal strings. The above example should be convert to '\r' which '\u000D' corresponds to.

like image 924
czheo Avatar asked Jan 05 '17 04:01

czheo


1 Answers

Use the unicode-escape codec.

>>> import codecs
>>> codecs.decode('\\u000D', 'unicode-escape')
'\r'
like image 80
dan04 Avatar answered Nov 14 '22 22:11

dan04