python console flush 覆盖输出/单行输出方式

in note-timknip •  4 years ago 

https://www.zhihu.com/question/21100416 这篇有第三方库的介绍

有时候看输出进度时,会分别输出进度,也就是输出一长串数字,如果能够覆盖之前的输出视觉效果会更好。
1
2
3
4
5
6
7
8
9

import sys
import time

for i in range(1000):
percent = 1.0 * i / 1000 * 100
sys.stdout.write("\r nihao: %d / %d" %(percent, 100))
sys.stdout.flush()

time.sleep(0.1)

以上这篇Python控制台输出时刷新当前行内容而不是输出新行的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!