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
ljcarsenal
V2EX  ›  Python

python shell 中有关 中文输出的问题

  •  
  •   ljcarsenal · 2014-02-27 19:31:45 +08:00 · 2928 次点击
    这是一个创建于 3731 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >>> s='中文'
    >>> s
    '\xd6\xd0\xce\xc4'
    >>> print s
    中文

    为什么直接s加回车会出现 unicode?
    4 条回复    1970-01-01 08:00:00 +08:00
    9hills
        1
    9hills  
       2014-02-27 19:52:35 +08:00 via iPad
    你那个s明显不是Unicode...

    S = u"中文" ,这才是unicode
    yakczh
        2
    yakczh  
       2014-02-27 20:31:58 +08:00
    >>> s='中文'
    >>> s
    '中文'
    xierch
        3
    xierch  
       2014-02-27 21:17:50 +08:00
    直接敲 s 是打印 s.__repr__() 的返回值
    7rack
        4
    7rack  
       2014-02-27 21:42:41 +08:00
    print s.encode('utf-8')
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3962 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:54 · PVG 08:54 · LAX 17:54 · JFK 20:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.