本文介绍了Python sys.stdout.flush() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码应该从 1 到 10 打印,中间间隔 1 秒,但是它在实际打印任何内容之前等待 10 秒,然后一次打印所有内容.如何取消缓冲输出?
The following code is supposed to print from 1 to 10 with 1 second intervals in between, however it is waiting for 10 seconds before actually printing anything and then it prints it all at once. How can I unbuffer the output?
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 只是不喜欢你.
Don't know why python is weird like this but apparently it accepted this. Your code should've worked fine but I guess python just didn't like you.
更多推荐
Python sys.stdout.flush() 不起作用
发布评论