V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
pc10201
V2EX  ›  Python

如何解决 python 2.7 在 sublime text3 console 输出的乱码问题?

  •  
  •   pc10201 · Feb 16, 2014 · 7614 views
    This topic created in 4466 days ago, the information mentioned may be changed or developed.
    因为要在cmd输出中文,所以我用unicode输出
    程序如下

    #coding=utf-8

    print u'中文测试'
    raw_input()

    在pycharm和cmd都能正常显示中文,但用sublime_text调试则出现

    Traceback (most recent call last):
    File "S:\test.py", line 3, in <module>
    print u'中文测试'
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

    求大神支招~
    5 replies    1970-01-01 08:00:00 +08:00
    tan9le
        1
    tan9le  
       Feb 16, 2014
    #coding=utf-8 -> # -*- coding:utf-8 -*-
    试下
    tan9le
        2
    tan9le  
       Feb 16, 2014
    参考:http://www.python.org/dev/peps/pep-0263/
    我也是Python初学
    binux
        3
    binux  
       Feb 16, 2014
    print u'中文测试'.encode("utf8")

    或者

    sys.setdefaultencoding("utf8")
    pc10201
        4
    pc10201  
    OP
       Feb 16, 2014
    @binux 以上方法都不行,好像是sublime_text输出的只能是utf-8编码,不能更改,算了,还是用pycharm吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:38 · PVG 05:38 · LAX 14:38 · JFK 17:38
    ♥ Do have faith in what you're doing.