第一种:普通进度条
# 普通进度条 import sys import time def test(): for i in range(1, 101): print(' ', end='') print('Download progress: {}%'.format(i), '▋' * (i//2), end='') sys.stdout.flush() time.sleep(0.05) test()
第二种:带时间的进度条
# 带时间进度条 import time def test(): start = time.perf_counter() for i in range(60+1): a = '*' * i b = '.' * (60 - i) c = (i / 60) * 100 dur = time.perf_counter() - start print(' {:^3.0f}%[{} - > {}]{:.2f}s'.format(c, a, b, dur), end='') time.sleep(0.1) test()
第三种:tqdm进度条
from tqdm import tqdm from time import sleep for i in tqdm(range(100)): sleep(0.1)