V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
commoccoom
V2EX  ›  问与答

python 下字符串编码的问题

  •  
  •   commoccoom · 2015-05-30 16:56:29 +08:00 · 2539 次点击
    这是一个创建于 3254 天前的主题,其中的信息可能已经有所发展或是发生改变。
    \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 条回复    2015-05-30 17:14:48 +08:00
    Sylv
        1
    Sylv  
       2015-05-30 17:02:23 +08:00
    >>> 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  
       2015-05-30 17:03:43 +08:00
    本来就是中文嘛...
    commoccoom
        3
    commoccoom  
    OP
       2015-05-30 17:06:37 +08:00
    @clino

    以中文显示
    Sylv
        4
    Sylv  
       2015-05-30 17:14:48 +08:00   ❤️ 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')
    来自:上海市 移动
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2844 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:36 · PVG 20:36 · LAX 05:36 · JFK 08:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.