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

加了 io.TextIOWrapper 处理后, print()内容就跟不上执行节奏了。。。

  •  
  •   pppguest3962 · Feb 13, 2020 · 3098 views
    This topic created in 2417 days ago, the information mentioned may be changed or developed.

    最近,从一些来源(如网页,MySQL)取得字符串后,print 会报错,但事实上字符只是带了一些东欧波兰语的字符,print()就无法处理了。。。
    根据网上的建议,加入:

    import sys, io
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
    

    然后,print 就能正常输出字符串了
    然而
    在大量处理(输出结果)的时候, 这些 print,会缓积到几百行的时候,才一下子在屏幕上显示出来,
    去掉上面两句,print 输出节奏,又像是以前一样了 这样对调试程序很不便, 如何配置 pycharm 或者修改程序,才能两种情况都能兼顾呢?

    1 replies  •  2020-02-15 11:11:29 +08:00
    frostming
        1
    frostming  
       Feb 15, 2020
    print(xxx, flush=True)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2726 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 07:11 · PVG 15:11 · LAX 00:11 · JFK 03:11
    ♥ Do have faith in what you're doing.