Unescaping Characters in a String with Python

前端 未结 2 741
鱼传尺愫
鱼传尺愫 2021-01-12 14:03

I made a JSON request that gives me a string that uses Unicode character codes that looks like:

s = \"\\u003Cp\\u003E\"

And I want to conve

相关标签:
2条回答
  • 2021-01-12 14:14
    >>> "\\u003Cp\\u003E".decode('unicode-escape')
    u'<p>'
    
    0 讨论(0)
  • 2021-01-12 14:18

    If the data came from JSON, the json module should already have decoded these escapes for you:

    >>> import json
    >>> json.loads('"\u003Cp\u003E"')
    u'<p>'
    
    0 讨论(0)
提交回复
热议问题