推荐学习书目
› 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
oldbird
V2EX  ›  Python

setdefaultencoding 后无法 print

  •  
  •   oldbird · Apr 16, 2019 · 1913 views
    This topic created in 2722 days ago, the information mentioned may be changed or developed.

    import sys

    reload(sys)

    sys.setdefaultencoding('utf-8')

    for t in range(100):

    print t
    

    py2.7 中,上述代码在 IDE 里无法打印出值,通过 cmd 运行正常; 注释掉前三句后,IDE 和 CMD 运行都正常。 不知道为什么?

    4 replies  •  2019-04-16 16:02:14 +08:00
    soulzz
        1
    soulzz  
       Apr 16, 2019
    python 中编码确实让人很头疼
    你代码顺序错了
    import sys
    sys.setdefaultencoding('utf-8')
    reload(sys)
    for t in range(100):
    print t
    ysc3839
        2
    ysc3839  
       Apr 16, 2019
    “无法打印出值”是怎么个无法?
    momo1999
        3
    momo1999  
       Apr 16, 2019
    是时候用 Python3 了
    oldbird
        4
    oldbird  
    OP
       Apr 16, 2019
    @shuax 主要是宿主软件必须用 py2.....
    找到解决方案了
    https://www.cnblogs.com/huangbiquan/p/7812005.html
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1164 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:16 · PVG 01:16 · LAX 10:16 · JFK 13:16
    ♥ Do have faith in what you're doing.