python包tqdm安装及入门

				版权声明:本文为博主原创文章,未经博主允许不得转载。					https://blog.csdn.net/rosefun96/article/details/78884687				</div>
							            <div id="content_views" class="markdown_views">
						<!-- flowchart 箭头图标 勿删 -->
						<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg>
						<h3 id="1安装"><a name="t0"></a>1、安装</h3>
pip install tqdm
 
 
  • 1

或者

conda install -c conda-forge tqdm
 
 
  • 1

2、tqdm的使用

进度条 tqdm 库比较热门,声称比老版的 python-progressbar 库的单次响应时间提高了 10 倍以上。

其实进度条的原理十分的简单,无非就是在 shell 中不断重写当前输出。

>>> from time import sleep
>>> from tqdm import tqdm
>>> for i in tqdm(range(1000)):
...     sleep(0.01)
...
  1%|▎                                        | 7/1000 [00:0
  2%|▌                                       | 15/1000 [00:0
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2.2结合循环,显示

from tqdm import tqdm

pbar = tqdm(range(300))#进度条

for i in pbar:
    err = 'abc'
    pbar.set_description("Reconstruction loss: %s" %(err))
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参考:

  1. 从 Python 第三方进度条库 tqdm 谈起
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值