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

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

  •  
  •   pc10201 · 2014-02-16 11:49:21 +08:00 · 7020 次点击
    这是一个创建于 3720 天前的主题,其中的信息可能已经有所发展或是发生改变。
    因为要在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 条回复    1970-01-01 08:00:00 +08:00
    tan9le
        1
    tan9le  
       2014-02-16 15:26:04 +08:00
    #coding=utf-8 -> # -*- coding:utf-8 -*-
    试下
    tan9le
        2
    tan9le  
       2014-02-16 15:27:57 +08:00
    参考:http://www.python.org/dev/peps/pep-0263/
    我也是Python初学
    binux
        3
    binux  
       2014-02-16 15:33:47 +08:00
    print u'中文测试'.encode("utf8")

    或者

    sys.setdefaultencoding("utf8")
    pc10201
        4
    pc10201  
    OP
       2014-02-16 16:32:53 +08:00
    @binux 以上方法都不行,好像是sublime_text输出的只能是utf-8编码,不能更改,算了,还是用pycharm吧
    nendors
        5
    nendors  
       2014-02-16 18:12:26 +08:00 via Android
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5286 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:41 · PVG 15:41 · LAX 00:41 · JFK 03:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.