本文介绍了如何刷新打印功能的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制将Python的打印功能输出到屏幕上?

How do I force Python's print function to output to the screen?

推荐答案

在Python 3上, print 可以接受可选的flush参数

On Python 3, print can take an optional flush argument

print("Hello world!", flush=True)

在Python 2上,您必须这样做

On Python 2 you'll have to do

import sys
sys.stdout.flush()

调用print后的

.默认情况下, print 打印到 sys.stdout (有关文件对象).

这篇关于如何刷新打印功能的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:27
查看更多