Python的打印函数在调用缓冲区时会刷新缓冲区? [英] Python's print function that flushes the buffer when it's called?

查看:155
本文介绍了Python的打印函数在调用缓冲区时会刷新缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复项:
如何刷新Python打印输出?
python中的非缓冲stdout(如python中-u)在程序中

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆