编程语言
首页 > 编程语言> > python动态打印进度条

python动态打印进度条

作者:互联网

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)




标签:content,进度条,python,打印,long,char,time,percentage,size
来源: https://www.cnblogs.com/jiyu-hlzy/p/15265740.html