commoccoom
V2EX  ›  问与答

python 下字符串编码的问题

  •  
  •   commoccoom · May 30, 2015 · 2982 views
    This topic created in 4027 days ago, the information mentioned may be changed or developed.
    \xe6\x9d\xa5\xe8\x87\xaa\xef\xbc\x9a\xe4\xb8\x8a\xe6\xb5\xb7\xe5\xb8\x82 \xe7\xa7\xbb\xe5\x8a\xa8

    怎么转成中文啊。
    4 replies    2015-05-30 17:14:48 +08:00
    Sylv
        1
    Sylv  
       May 30, 2015
    >>> print '\xe6\xac\xa2\xe8\xbf\x8e\xe6\x8f\x90\xe4\xba\xa4\xe5\xbe\xae\xe5\x8d\x9a\xe6\x90\x9c\xe7\xb4\xa2\xe4\xbd\xbf\xe7\x94\xa8\xe5\x8f\x8d\xe9\xa6\x88\xef\xbc\x8c\xe8\xaf\xb7\xe7\x9b\xb4\xe6\x8e\xa5'
    欢迎提交微博搜索使用反馈,请直接
    clino
        2
    clino  
       May 30, 2015
    本来就是中文嘛...
    commoccoom
        3
    commoccoom  
    OP
       May 30, 2015
    @clino

    以中文显示
    Sylv
        4
    Sylv  
       May 30, 2015   ❤️ 1
    >>> print '\xe6\x9d\xa5\xe8\x87\xaa\xef\xbc\x9a\xe4\xb8\x8a\xe6\xb5\xb7\xe5\xb8\x82 \xe7\xa7\xbb\xe5\x8a\xa8'
    来自:上海市 移动

    >>> s = u"\xe6\x9d\xa5\xe8\x87\xaa\xef\xbc\x9a\xe4\xb8\x8a\xe6\xb5\xb7\xe5\xb8\x82 \xe7\xa7\xbb\xe5\x8a\xa8"
    >>> print s.encode('latin-1')
    来自:上海市 移动
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2562 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:00 · PVG 00:00 · LAX 09:00 · JFK 12:00
    ♥ Do have faith in what you're doing.