Tqdm 是 Python 进度条库,可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator)

# 方法1:
import time
from tqdm import tqdm for i in tqdm(range(100)):
time.sleep(0.01) 方法2:
import time
from tqdm import trange for i in trange(100):
time.sleep(0.01)

  

结果:

 0%|          | 0/100 [00:00<?, ?it/s]
11%|█ | 11/100 [00:00<00:00, 100.00it/s]
22%|██▏ | 22/100 [00:00<00:00, 100.00it/s]
32%|███▏ | 32/100 [00:00<00:00, 100.00it/s]
43%|████▎ | 43/100 [00:00<00:00, 100.00it/s]
54%|█████▍ | 54/100 [00:00<00:00, 100.00it/s]
64%|██████▍ | 64/100 [00:00<00:00, 99.11it/s]
74%|███████▍ | 74/100 [00:00<00:00, 99.37it/s]
85%|████████▌ | 85/100 [00:00<00:00, 99.56it/s]
95%|█████████▌| 95/100 [00:00<00:00, 99.69it/s]
100%|██████████| 100/100 [00:01<00:00, 99.70it/s]

可以为进度条设置描述:

import time
from tqdm import tqdm pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
# 设置描述
pbar.set_description("Processing %s" % char)
time.sleep(1)

  

结果:

0%|          | 0/4 [00:00<?, ?it/s]
Processing a: 25%|██▌ | 1/4 [00:01<00:03, 1.00it/s]
Processing b: 50%|█████ | 2/4 [00:02<00:02, 1.00it/s]
Processing c: 75%|███████▌ | 3/4 [00:03<00:01, 1.00it/s]
Processing d: 100%|██████████| 4/4 [00:04<00:00, 1.00it/s]
import time
from tqdm import tqdm # 一共200个,每次更新10,一共更新20次
with tqdm(total=200) as pbar:
for i in range(20):
pbar.update(10)
time.sleep(0.1) #方法2:
pbar = tqdm(total=200)
for i in range(20):
pbar.update(10)
time.sleep(0.1)
# close() 不要也没出问题?
pbar.close()

结果:

  0%|          | 0/200 [00:00<?, ?it/s]
15%|█▌ | 30/200 [00:00<00:01, 150.00it/s]
25%|██▌ | 50/200 [00:00<00:01, 130.43it/s]
30%|███ | 60/200 [00:00<00:01, 119.52it/s]
40%|████ | 80/200 [00:00<00:01, 112.91it/s]
50%|█████ | 100/200 [00:00<00:00, 108.70it/s]
55%|█████▌ | 110/200 [00:01<00:00, 105.93it/s]
65%|██████▌ | 130/200 [00:01<00:00, 104.08it/s]
75%|███████▌ | 150/200 [00:01<00:00, 102.82it/s]
80%|████████ | 160/200 [00:01<00:00, 101.96it/s]
85%|████████▌ | 170/200 [00:01<00:00, 96.38it/s]
90%|█████████ | 180/200 [00:01<00:00, 97.44it/s]
100%|██████████| 200/200 [00:01<00:00, 98.19it/s]

更多用法,学习完后再补充:
https://blog.csdn.net/langb2014/article/details/54798823?locationnum=8&fps=1

python 中有趣的库tqdm的更多相关文章

  1. 【归纳】正则表达式及Python中的正则库

    正则表达式 正则表达式30分钟入门教程 runoob正则式教程 正则表达式练习题集(附答案) 元字符\b代表单词的分界处,在英文中指空格,标点符号或换行 例子:\bhi\b可以用来匹配hi这个单词,且 ...

  2. 利用Python中的mock库对Python代码进行模拟测试

    这篇文章主要介绍了利用Python中的mock库对Python代码进行模拟测试,mock库自从Python3.3依赖成为了Python的内置库,本文也等于介绍了该库的用法,需要的朋友可以参考下     ...

  3. Python中使用第三方库xlrd来写入Excel文件示例

    Python中使用第三方库xlrd来写入Excel文件示例 这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表 ...

  4. 【转】利用Python中的mock库对Python代码进行模拟测试

    出处 https://www.toptal.com/python/an-introduction-to-mocking-in-python http://www.oschina.net/transla ...

  5. 从 Python 第三方进度条库 tqdm 谈起 (转载)

    原文地址: https://blog.ernest.me/post/python-progress-bar tqdm 最近一款新的进度条 tqdm 库比较热门,声称比老版的 python-progre ...

  6. python中的turtle库绘制图形

    1. 前奏: 在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块 ...

  7. Python中的BeautifulSoup库简要总结

    一.基本元素 BeautifulSoup库是解析.遍历.维护“标签树”的功能库. 引用 from bs4 import BeautifulSoup import bs4 html文档-标签树-Beau ...

  8. Python中关于第三方库的补充

    Python语言的强大之处在于它的开源.正是因为它的开源,产生了成百上千的第三方库,涵盖了计算机的几乎所有的方向.第三方库的安装也并不是特别的复杂,通过在cmd中使用pip命令可以安装几乎所有的库,但 ...

  9. python中的Matplot库和Gdal库绘制富士山三维地形图-参考了虾神的喜马拉雅山

    首先请大家读一下面这篇文章了解什么是Gdal http://blog.csdn.net/grllery/article/details/77822595 剩下的我要公布绘制富士山的代码了,虽然基本co ...

随机推荐

  1. 987. Binary Number with Alternating Bits

    Description Given a positive integer, check whether it has alternating bits: namely, if two adjacent ...

  2. excel 删除重复项

    excel 删除重复项 单击“数据”按钮会出现如图所示,这时我们可以看到,在下分的菜单栏里有一个“删除重复项”选项,单击该选项.

  3. 2017-10-5-Python

    想学习Python很长时间了,工作中使用Python脚本解决问题真的很爽. 插入一张Python的py文件常见的结构图: if __name__ =="__main__" 这条语句 ...

  4. 2017-9-12-Linux移植&驱动开发

    准备学习Linux很长时间了,很大的一个原因就是兴趣,Linux对科技进步发展.人们生活的改变影响之深很难用简简单单的一些话描述清楚.跟Linux密切相关的东西,开源软件.c语言.底层驱动.网络.服务 ...

  5. go channel tips

    一.只有一个goroutine时,读写阻塞的chan会出错(“fatal error: all goroutines are asleep - deadlock!”).包括未make的chan(cha ...

  6. 使用scrapy爬取百度股票

    1.spiders文件夹下的爬虫文件 # -*- coding: utf-8 -*- import scrapy import re import random from scrapy.http.re ...

  7. Linux之经典互联网架构

    经典互联网架构 netstat -tulnp |grep 80ss -tulnp|grep 80 前期铺垫: 1. Linux要能上网2. 掌握Linux软件包安装方法2.1 rpm包管理 2.1.1 ...

  8. 移动游戏ui设计(二)--游戏世界的基本法则

    游戏世界的基本法则游戏体验的层次感很重要,制作一款趣味性强,宗旨明确的游戏并不简单. l  风格统一性:要先明白游戏的game genres,因为游戏类型与风格密切联系.常见游戏类型有:动作类.冒险类 ...

  9. windows下安装Mysql—图文详解

    mysql安装过程及注意事项: 1.1. 下载: 我下载的是64位系统的zip包: 下载地址:https://dev.mysql.com/downloads/mysql/ 下载zip的包: 下载后解压 ...

  10. Java基础知识--集合

    集合类 数组和集合的比较:数组可以存储对象,也可以存储基本数据类型,但是缺点就是长度固定,不能改变:集合长度是可变的,但是集合只能存储对象,集合可以存储不同类型的对象. Java容器类库一共有两种主要 ...