【Python进度条】基于tqdm

【Python进度条】tqdm详解

转载至https://zhuanlan.zhihu.com/p/163613814
在迭代时若想看到程序运行进度,并且不想打印迭代数,这时就需要使用进度条来展示。tqdm是Python的进度条库。

tqdm有两种运行模式:

  • 1.基于迭代对象进行
  • 2.手动更新

基于迭代对象:tqdm(iterator)

import time
import tqdm
start = time.perf_counter()
######## 实际程序开始 ##########
for i in tqdm.tqdm(range(10000)):
	for j in range(10000):
		pass
######## 实际程序结束 ##########
end = time.perf_counter()
print("运行时间为", round(end-start), 'seconds')

手动更新

import time
from tqdm import tqdm

with tqdm(total=200) as pbar:
    pbar.set_description('Processing:')
    # total表示总的项目, 循环的次数20*10(每次更新数目) = 200(total)
    for i in range(20):
        # 进行动作, 这里是过0.1s
        time.sleep(0.1)
        # 进行进度更新, 这里设置10个
        pbar.update(10)
Processing:: 100%|██████████| 200/200 [00:02<00:00, 91.94it/s]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值