How to unquote a urlencoded unicode string in python?

后端 未结 5 1603
时光说笑
时光说笑 2020-11-29 00:23

I have a unicode string like \"Tanım\" which is encoded as \"Tan%u0131m\" somehow. How can i convert this encoded string back to original unicode. Apparently urllib.unquote

5条回答
  •  醉梦人生
    2020-11-29 01:00

    This will do it if you absolutely have to have this (I really do agree with the cries of "non-standard"):

    from urllib import unquote
    
    def unquote_u(source):
        result = unquote(source)
        if '%u' in result:
            result = result.replace('%u','\\u').decode('unicode_escape')
        return result
    
    print unquote_u('Tan%u0131m')
    
    > Tanım
    

提交回复
热议问题