Python sys.stdout.flush() 不起作用

编程入门 行业动态 更新时间:2024-10-26 22:21:33
本文介绍了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() 不起作用

本文发布于:2023-10-09 10:35:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475504.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   sys   Python   flush   stdout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!