这里主要是有两个方法:tqdm 和 progressbar
1. 首先是tqdm方法:
from time import sleep from tqdm import tqdm for i in tqdm(range(10)): # 需要循环或者多次执行的代码 print('\n the value of i is %d ---'%i) #正常的整数值:i for ii in range(i): print(ii) sleep(0.1)
2. 其次是progressbar方法
from progressbar import ProgressBar, Percentage, Bar, Timer, ETA, FileTransferSpeed aa = [1,2,3,4,5,6,7,8,9] total = len(aa) def dowith_i(i): for ii in range(i): print(ii) sleep(0.1) widgets = ['当前进度: ',Percentage(), ' ', Bar('=>'),' ', Timer(), ' ', ETA(), ' ', FileTransferSpeed()] bar_object = ProgressBar(widgets=widgets, maxval=10*total).start() for i in range(total): print('\n') dowith_i(i) #做自己的任务 bar_object.update(10 * i + 1) bar_object.finish()
其中 'widgets' 参数可以自己设置。
Timer:表示经过的秒(时间)
Bar:设置进度条形状
Percentage:显示百分比进度
ETA:预估剩余时间
FileTransferSpeed:文件传输速度
参考:
https://baijiahao.baidu.com/s?id=1604219346207216803&wfr=spider&for=pc