Vyacheslav
Vyacheslav

Reputation: 27221

How can I convert UTF-8 to escaped string

I've got u'≈'.encode('unicode_escape')

I want to receive "\u2248" as string.

Upvotes: 2

Views: 137

Answers (1)

Malcolm
Malcolm

Reputation: 41510

I think I've figured out a way to do that. You can do .decode('ascii') right on the string, then it will give you back the encoded string, for example:

"🙂".encode("unicode_escape").decode('ascii')

gives you

'\\U0001f642'

Upvotes: 2

Related Questions