czheo
czheo

Reputation: 1941

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.

Upvotes: 6

Views: 1432

Answers (1)

dan04
dan04

Reputation: 90995

Use the unicode-escape codec.

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

Upvotes: 11

Related Questions