Python的打印函数在调用缓冲区时刷新缓冲区?
问题描述:
可能重复:
How to flush output of Python print?
unbuffered stdout in python (as in python -u) from within the programPython的打印函数在调用缓冲区时刷新缓冲区?
我有下面的代码,以冲洗掉输出缓冲区。
print 'return 1'
sys.stdout.flush()
我可以设置打印功能,以便它在被调用时自动刷新缓冲区?
答
您可以使用-u标志以非缓冲模式启动python,例如,
python -u script.py
或
#!/usr/bin/env python -u
为 “认领” 头为你的脚本。
嗯,乱了我的链接,应该是:[在Python中无缓冲标准输出](http://*.com/questions/881696/unbuffered-stdout-in-python-as-in-python-u-from -within最程序) – eldarerathis 2010-10-09 03:05:31