本文介绍了如何刷新打印功能的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制Python的 print
函数输出到屏幕上?
How do I force Python's print
function to output to the screen?
推荐答案
在Python 3中, print
可以采用可选的 flush
参数:
In Python 3, print
can take an optional flush
argument:
print("Hello, World!", flush=True)
在Python 2中,您必须这样做
In Python 2 you'll have to do
import sys
sys.stdout.flush()
在调用 print
之后.默认情况下, print
打印到 sys.stdout
(请参阅文档以获取有关文件对象的更多信息.
after calling print
. By default, print
prints to sys.stdout
(see the documentation for more about file objects).
这篇关于如何刷新打印功能的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!