python动态打印进度条

时间:2021-09-15 17:45:10   收藏:0   阅读:37
import time

start_time = time.time()
# 内容总大小
content_size = 100
# 进度条字符
char_str = ‘>‘
# 进度条字符长度
char_long = 50
for size in range(content_size + 1):
    # 已完成的百分比
    percentage = size / content_size
    print(‘\r‘,
          f‘进度:[%-{char_long}s%.2f%%]耗时:%.1fs‘ % (
              char_str * int(char_long * percentage), percentage * 100, time.time() - start_time),
          end=‘‘)
    # 间隔时间、更直观的效果
    time.sleep(0.1)




原文:https://www.cnblogs.com/jiyu-hlzy/p/15265740.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!