gpt4 book ai didi

python-3.x - Python sys.stdout.flush() 不起作用

转载 作者:行者123 更新时间:2023-12-02 17:27:45 24 4
gpt4 key购买 nike

下面的代码应该打印从 1 到 10,中间间隔 1 秒,但是它在实际打印任何内容之前等待 10 秒,然后一次性打印所有内容。如何取消缓冲输出?

import sys
import time
for count in range(10) :
sys.stdout.write(str(count))
sys.stdout.flush()
time.sleep(1)

最佳答案

发现问题

import sys
import time
for count in range(10) :
sys.stdout.write("\b%s" % count)
sys.stdout.flush()
time.sleep(.1)

不知道为什么 python 这么奇怪,但显然它接受了这一点。你的代码应该可以正常工作,但我猜 python 只是不喜欢你。

关于python-3.x - Python sys.stdout.flush() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com