欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python print不能立即打印的解決方式

 更新時(shí)間:2020年02月19日 14:01:39   作者:郭老二  
今天小編就為大家分享一篇Python print不能立即打印的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

1、問(wèn)題描述

在Python中使用print打印hello world時(shí),終端不顯示

def hello():
 print("hello world!")

2、原因

因?yàn)闃?biāo)準(zhǔn)輸入輸出stdin/stdout有緩沖區(qū),所以使用print不能立即打印出來(lái),作為剛接觸Python的菜鳥(niǎo),迷瞪了半天

3、解決方法

1)刷新緩沖區(qū),python中是sys.stdout.flush()

import sys 
def hello():
 print("hello world!")
 sys.stdout.flush()

2)python3中支持print支持參數(shù)flush

原型:

print(*objects, sep=' ‘, end='\n', file=sys.stdout, flush=False)

def hello():
 print("hello world!", flush=True)

參考官方手冊(cè)

https://docs.python.org/zh-cn/3/library/functions.html#print

以上這篇Python print不能立即打印的解決方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論