V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wdg8106
V2EX  ›  Python

python2 编码问题请教

  •  
  •   wdg8106 · 2016-12-12 15:50:27 +08:00 · 1605 次点击
    这是一个创建于 2663 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如一个字符串:
    a = '哈哈'

    解码后 a.decode('utf-8')输出的是:
    u'\u54c8\u54c8'

    但是现在接收到的字符串是 '\u54c8\u54c8' 这种类型的,看起来是 unicode 的字节,但是是 str 类型, 该怎样处理呢
    2 条回复    2016-12-12 17:10:17 +08:00
    Sylv
        1
    Sylv  
       2016-12-12 16:21:45 +08:00 via iPhone   ❤️ 4
    '\u54c8\u54c8'.decode('unicode-escape')
    wdg8106
        2
    wdg8106  
    OP
       2016-12-12 17:10:17 +08:00
    @Sylv 多谢~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5353 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 07:32 · PVG 15:32 · LAX 00:32 · JFK 03:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.