Search code examples
pythonpython-3.xpython-unicode

Python 3: How to convert unicode text in original form?


I am getting text in form Al\\\\u0027sPlace which actually is Al's Place. Same is for ‘â\x80\x94

How do I get Al's Place in original form?


Solution

  • Seems like it encoded with unicode-escape encoding twice; reverse it.

    >>> text = 'Al\\\\u0027sPlace'
    >>> text.encode().decode('unicode-escape').encode().decode('unicode-escape')
    "Al'sPlace"