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 谈起
				版权声明:本文为博主原创文章,未经博主允许不得转载。					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>

猜你喜欢

转载自blog.csdn.net/qq_31511955/article/details/85246463