python实现原地刷新方式输出-可用于百分比进度显示输出

方式1:

import sys

sys.stdout.write(\r + 你的输出详情)
sys.stdout.flush()

 

方式2:

print(\r + 你的输出详情, end=‘‘, flush=True)

 

实例:

import sys
import time

for i in range(101):
    # 方式1
    sys.stdout.write(\r + str(i))
    sys.stdout.flush()
    # 方式2
    print(\r + str(i), end=‘‘, flush=True)

    time.sleep(0.3)

 

文章来自:https://www.cnblogs.com/007sx/p/9420443.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3