`; switch(displayFormat) { case 'text-only': html += `
${description}
`; break; case 'small-with-description': html += `
${imgSmallUrl ? `
` : ''}
${description}
`; break; case 'banner-only': html += `
`; break; case 'big-only': html += `
`; break; case 'big-with-description': html += `
`; html += `
${description}
`; break; case 'big-with-title-description-button': html += `
`; html += `
${description}
`; html += ``; break; default: html += `
${description}
`; } html += `
${promotedBy}
PRO
` return html; } // Load campaign from emitter var xhr = new XMLHttpRequest(); xhr.open('GET', '/pro/emitter', true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200) { try { var campaign = JSON.parse(xhr.responseText); if (campaign && campaign.id) { var html = renderCampaign(campaign); var container = document.getElementById('pro-campaign-container'); if (html) { container.innerHTML = html; bindCampaignLinks(container); } else { container.style.display = 'none'; } } else { document.getElementById('pro-campaign-container').style.display = 'none'; } } catch (e) { document.getElementById('pro-campaign-container').style.display = 'none'; console.log('Error parsing campaign data: ' + e.message); } } else { document.getElementById('pro-campaign-container').style.display = 'none'; console.log('Error loading campaign: HTTP ' + xhr.status); } } }; xhr.send(); });
推荐学习书目
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 · 7695 views
    This topic created in 4516 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   ·   3027 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 14:27 · PVG 22:27 · LAX 07:27 · JFK 10:27
    ♥ Do have faith in what you're doing.