6

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.

1 Answer 1

11

Use the unicode-escape codec.

>>> import codecs
>>> codecs.decode('\\u000D', 'unicode-escape')
'\r'
Sign up to request clarification or add additional context in comments.

1 Comment

the same result without codecs - '\\u000D'.encode('ascii').decode('unicode-escape') or with other encoding '\\u000D'.encode('utf-8').decode('unicode-escape')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.