Python: how to convert utf-8 code string back to string?

后端 未结 3 2121
遥遥无期
遥遥无期 2020-12-15 01:52

I am using Python and unfortunately my code needs to convert a string that represents the utf-8 code of a string in to the original string, like:

UTF-8 code string t

3条回答
  •  粉色の甜心
    2020-12-15 02:37

    Mark Pilgrim had explained this in his book. Take a look

    http://www.diveintopython.net/xml_processing/unicode.html

    >>> s = u"\u6b22\u8fce\u63d0\u4ea4\u5fae\u535a\u641c\u7d22\u4f7f\u7528\u53cd\u9988\uff0c\u8bf7\u76f4\u63a5"
    
    >>> print s.encode("utf-8")
    
    >>> 欢迎提交微博搜索使用反馈,请直接
    

提交回复
热议问题