tqdm模块
tqdm 是 Python 进度条库。
tqdm库下面有2个类我们经常使用:
1.
2.
可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator)
trange(i) 是 tqdm(range(i)) 的简单写法。
可以总结为三个方法:
方法一:
- # 方法1:
- import time
- from tqdm import tqdm
- for i in tqdm(range()):
- time.sleep(0.01)
- 方法1+:
- import time
- from tqdm import trange
- for i in trange():
- time.sleep(0.01)
结果如下:
- %| | / [:<?, ?it/s]
- %|█ | / [:<:, .10it/s]
- %|██ | / [:<:, .77it/s]
- %|███ | / [:<:, .71it/s]
- %|████ | / [:<:, .49it/s]
- %|█████ | / [:<:, .56it/s]
- %|██████ | / [:<:, .82it/s]
- %|███████ | / [:<:, .57it/s]
- %|████████ | / [:<:, .44it/s]
- %|█████████ | / [:<:, .82it/s]
- %|██████████| / [:<:, .81it/s]
- %|██████████| / [:<:, .91it/s]
- %| | / [:<?, ?it/s]
- %|█ | / [:<:, .74it/s]
- %|██ | / [:<:, .20it/s]
- %|███ | / [:<:, .83it/s]
- %|████ | / [:<:, .83it/s]
- %|█████ | / [:<:, .57it/s]
- %|██████ | / [:<:, .90it/s]
- %|███████ | / [:<:, .88it/s]
- %|████████ | / [:<:, .00it/s]
- %|█████████ | / [:<:, .69it/s]
- %|██████████| / [:<:, .76it/s]
- %|██████████| / [:<:, .71it/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(0.2)
- %| | / [:<?, ?it/s]
- Processing a: %| | / [:<?, ?it/s]
- Processing a: %|██▌ | / [:<:, .99it/s]
- Processing b: %|██▌ | / [:<:, .99it/s]
- Processing b: %|█████ | / [:<:, .99it/s]
- Processing c: %|█████ | / [:<:, .99it/s]
- Processing c: %|███████▌ | / [:<:, .99it/s]
- Processing d: %|███████▌ | / [:<:, .99it/s]
- Processing d: %|██████████| / [:<:, .99it/s]
- Processing d: %|██████████| / [:<:, .99it/s]
方法三:手动更新
- import time
- from tqdm import tqdm
- # 一共200个,每次更新10,一共更新20次
- with tqdm(total=200) as pbar:
- pbar.set_description("Processing")
- 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)
- pbar.close()
- 0%| | 0/200 [00:00<?, ?it/s]
- Processing: 0%| | 0/200 [00:00<?, ?it/s]
- Processing: 10%|█ | 20/200 [00:00<00:00, 198.53it/s]
- Processing: 15%|█▌ | 30/200 [00:00<00:01, 152.68it/s]
- Processing: 20%|██ | 40/200 [00:00<00:01, 131.50it/s]
- Processing: 25%|██▌ | 50/200 [00:00<00:01, 119.83it/s]
- Processing: 30%|███ | 60/200 [00:00<00:01, 112.82it/s]
- Processing: 35%|███▌ | 70/200 [00:00<00:01, 108.39it/s]
- Processing: 40%|████ | 80/200 [00:00<00:01, 105.48it/s]
- Processing: 45%|████▌ | 90/200 [00:00<00:01, 103.54it/s]
- Processing: 50%|█████ | 100/200 [00:00<00:00, 102.21it/s]
- Processing: 55%|█████▌ | 110/200 [00:01<00:00, 101.32it/s]
- Processing: 60%|██████ | 120/200 [00:01<00:00, 100.70it/s]
- Processing: 65%|██████▌ | 130/200 [00:01<00:00, 100.27it/s]
- Processing: 70%|███████ | 140/200 [00:01<00:00, 100.17it/s]
- Processing: 75%|███████▌ | 150/200 [00:01<00:00, 100.00it/s]
- Processing: 80%|████████ | 160/200 [00:01<00:00, 99.78it/s]
- Processing: 85%|████████▌ | 170/200 [00:01<00:00, 99.75it/s]
- Processing: 90%|█████████ | 180/200 [00:01<00:00, 99.60it/s]
- Processing: 95%|█████████▌| 190/200 [00:01<00:00, 99.71it/s]
- Processing: 100%|██████████| 200/200 [00:01<00:00, 99.68it/s]
- Processing: 100%|██████████| 200/200 [00:02<00:00, 99.39it/s]
- 0%| | 0/200 [00:00<?, ?it/s]
- 10%|█ | 20/200 [00:00<00:00, 198.60it/s]
- 15%|█▌ | 30/200 [00:00<00:01, 152.73it/s]
- 20%|██ | 40/200 [00:00<00:01, 131.51it/s]
- 25%|██▌ | 50/200 [00:00<00:01, 119.83it/s]
- 30%|███ | 60/200 [00:00<00:01, 112.82it/s]
- 35%|███▌ | 70/200 [00:00<00:01, 108.38it/s]
- 40%|████ | 80/200 [00:00<00:01, 105.37it/s]
- 45%|████▌ | 90/200 [00:00<00:01, 103.56it/s]
- 50%|█████ | 100/200 [00:00<00:00, 102.19it/s]
- 55%|█████▌ | 110/200 [00:01<00:00, 101.52it/s]
- 60%|██████ | 120/200 [00:01<00:00, 100.93it/s]
- 65%|██████▌ | 130/200 [00:01<00:00, 100.43it/s]
- 70%|███████ | 140/200 [00:01<00:00, 100.08it/s]
- 75%|███████▌ | 150/200 [00:01<00:00, 100.04it/s]
- 80%|████████ | 160/200 [00:01<00:00, 99.90it/s]
- 85%|████████▌ | 170/200 [00:01<00:00, 99.92it/s]
- 90%|█████████ | 180/200 [00:01<00:00, 99.81it/s]
- 95%|█████████▌| 190/200 [00:01<00:00, 99.86it/s]
- 100%|██████████| 200/200 [00:01<00:00, 99.78it/s]
- 100%|██████████| 200/200 [00:02<00:00, 99.47it/s]
tqdm模块的更多相关文章
- hdf5文件、tqdm模块、nunique、read_csv、sort_values、astype、fillna
pandas.DataFrame.to_hdf(self, path_or_buf, key, **kwargs): Hierarchical Data Format (HDF) ,to add an ...
- [Python]-tqdm模块-给for循环加上进度条
import tqdm 使用tqdm模块,可以在漫长的for循环加上一个进度条,显示当前进度百分比. 将tqdm写在迭代器之外即可:tqdm(iterator) for i in tqdm(range ...
- (数据科学学习手札53)Python中tqdm模块的用法
一.简介 tqdm是Python中专门用于进度条美化的模块,通过在非while的循环体内嵌入tqdm,可以得到一个能更好展现程序运行过程的提示进度条,本文就将针对tqdm的基本用法进行介绍. 二.基本 ...
- python的tqdm模块
Tqdm 是一个快速,可扩展的Python进度条,可以在 Python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator). 根据要求安装依赖即可. 可以很方便的在 ...
- python的tqdm模块介绍
https://www.jianshu.com/p/b27318efdb7b Tqdm 是 Python 进度条库,可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator) ...
- python实现进度条
先说一下文本系统的控制符: \r: 将光标移动到当前行的首位而不换行: \n: 将光标移动到下一行,并不移动到首位: \r\n: 将光标移动到下一行首位. 环境: root@ubuntu16:/ale ...
- 万能的Python,还能用来制作高大上的进度条?
对于开发或者运维来说,使用Python去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效的监控任务的进度,除了在任务中加上log外,还能不能有另一种方式来了解任务进展到哪一步了呢? ...
- 【Python】给程序加个进度条
对于开发或者运维来说,使用 Python 去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效地监控任务的进度?除了在任务中加上 Log 外,还能不能有另一种方式来了解任务进展到哪一步 ...
- 用 Python 给程序加个进度条,让你的看起来更炫酷?
对于开发或者运维来说,使用 Python 去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效地监控任务的进度?除了在任务中加上 Log 外,还能不能有另一种方式来了解任务进展到哪一步 ...
随机推荐
- 【1.1】mysql frm文件丢失(ibd文件丢失)
[1]故障模拟准备环境 这里以innodb为例 [1.1]配置参数 开启独立表空间 innodb_file_per_table; [1.2]构建测试数据 create database test; c ...
- Shell脚本中计算字符串长度的5种方法
有时在Linux操作系统中需要计算某个字符串的长度,通过查询资料整理了下目前Shell中获取字符串的长度的多种方法,在这里分享给大家,方法如下: 方法1: 使用wc -L命令wc -L可以获取到当前行 ...
- 服务器:消息18456,级别16,状态1 用户‘sa’登录失败解决方法
无法连接到服务器**: 服务器:消息18456,级别16,状态1 [Microsoft][ODBC SQL Server Driver][Sql server] 用户 'sa ...
- Yii2.0 组件
框架之所以是框架,是因为其强大,其封装了很多实用的功能,开发者可以开箱即用. 下边列举Yii2.0的部分组件: var_dump(Yii::$app->session->getId()); ...
- 在Window Server 2016中使用Web Deploy方式发布.NET Web应用
1.在IIS里面点击获取新的Web平台组件 2.下载Web平台组件并安装 3.在其中搜索Web Deploy,找到3.5版本,并安装 4.继续搜索Web Deploy 3.6版本,并安装 安装好之后, ...
- OnMouseWheel的通常处理
BOOL CMainWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint point) { BOOL bUp = TRUE; int nDelt ...
- axios配置
import axios, { isCancel } from 'axios' import { md5 } from 'vux' import util from '@/libs/util' imp ...
- 在Global.asax中 注册Application_Error事件 捕获全局异常
参考于:https://shiyousan.com/post/635813858052755170 在ASP.NET MVC中,通过应用程序生命周期中的Application_Error事件可以捕获到 ...
- BZOJ4241历史研究题解--回滚莫队
题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=4241 分析 这题就是求区间权值乘以权值出现次数的最大值,一看莫队法块可搞,但仔细想想,莫 ...
- LeetCode:595.大的国家
题目链接:https://leetcode-cn.com/problems/big-countries/ 题目 这里有张 World 表 +-----------------+------------ ...