推荐学习书目
› 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 · 7830 views
    This topic created in 4604 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   ·   Privacy   ·   Solana   ·   2907 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:05 · PVG 11:05 · LAX 20:05 · JFK 23:05
    ♥ Do have faith in what you're doing.