Python's print function that flushes the buffer when it's called? [duplicate]

谁说我不能喝 提交于 2019-12-09 09:41:07

问题


Possible Duplicates:
How to flush output of Python print?
unbuffered stdout in python (as in python -u) from within the program

I have the following code to flushing out the output buffer.

print 'return 1'
sys.stdout.flush()

Can I setup the print function so that it automatically flushes the buffer when it's called?


回答1:


You can start python in unbuffered mode using the -u flag, e.g.

python -u script.py

or

#!/usr/bin/env python -u

as "shebang" header for your script.



来源:https://stackoverflow.com/questions/3895481/pythons-print-function-that-flushes-the-buffer-when-its-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!