Python的打印函数在调用缓冲区时会刷新缓冲区? [英] Python's print function that flushes the buffer when it's called?
本文介绍了Python的打印函数在调用缓冲区时会刷新缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案
您可以使用-u标志以无缓冲模式启动python,例如
You can start python in unbuffered mode using the -u flag, e.g.
python -u script.py
或
#!/usr/bin/env python -u
作为脚本的"shebang"标题.
as "shebang" header for your script.
这篇关于Python的打印函数在调用缓冲区时会刷新缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文