python 中有趣的库tqdm
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的更多相关文章
- 【归纳】正则表达式及Python中的正则库
正则表达式 正则表达式30分钟入门教程 runoob正则式教程 正则表达式练习题集(附答案) 元字符\b代表单词的分界处,在英文中指空格,标点符号或换行 例子:\bhi\b可以用来匹配hi这个单词,且 ...
- 利用Python中的mock库对Python代码进行模拟测试
这篇文章主要介绍了利用Python中的mock库对Python代码进行模拟测试,mock库自从Python3.3依赖成为了Python的内置库,本文也等于介绍了该库的用法,需要的朋友可以参考下 ...
- Python中使用第三方库xlrd来写入Excel文件示例
Python中使用第三方库xlrd来写入Excel文件示例 这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表 ...
- 【转】利用Python中的mock库对Python代码进行模拟测试
出处 https://www.toptal.com/python/an-introduction-to-mocking-in-python http://www.oschina.net/transla ...
- 从 Python 第三方进度条库 tqdm 谈起 (转载)
原文地址: https://blog.ernest.me/post/python-progress-bar tqdm 最近一款新的进度条 tqdm 库比较热门,声称比老版的 python-progre ...
- python中的turtle库绘制图形
1. 前奏: 在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块 ...
- Python中的BeautifulSoup库简要总结
一.基本元素 BeautifulSoup库是解析.遍历.维护“标签树”的功能库. 引用 from bs4 import BeautifulSoup import bs4 html文档-标签树-Beau ...
- Python中关于第三方库的补充
Python语言的强大之处在于它的开源.正是因为它的开源,产生了成百上千的第三方库,涵盖了计算机的几乎所有的方向.第三方库的安装也并不是特别的复杂,通过在cmd中使用pip命令可以安装几乎所有的库,但 ...
- python中的Matplot库和Gdal库绘制富士山三维地形图-参考了虾神的喜马拉雅山
首先请大家读一下面这篇文章了解什么是Gdal http://blog.csdn.net/grllery/article/details/77822595 剩下的我要公布绘制富士山的代码了,虽然基本co ...
随机推荐
- Mysql You can change this value on the server by setting the max_allowed_packet' variable. 异常
MySQL根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会被max_allowed_packet 参数限制掉,导致失败. 查看目前配置, Windows 系统 配置文件为 my ...
- Spring cloud Eureka错误锦集(一)
初学Spring cloud的时候,启动Eureka的时候报了下面的错误: com.sun.jersey.api.client.ClientHandlerException: java.net.Con ...
- 2153 ACM 仙人球的残影 输出格式
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2153 中文题目,很简单,但是要注意输出格式,题目中三个字符长度 输出格式:%3d (整数) 思路:将输出看 ...
- yii2场景的应用(scenarios)
例如: 现在在 post表里面有 title image content 三个的字段,当我创建一个 post 的时候,我想三个字段全部是必填项,但是你修改的时候,title content 两个字段是 ...
- PAT-Top1001. Battle Over Cities - Hard Version (35)
在敌人占领之前由城市和公路构成的图是连通图.在敌人占领某个城市之后所有通往这个城市的公路就会被破坏,接下来可能需要修复一些其他被毁坏的公路使得剩下的城市能够互通.修复的代价越大,意味着这个城市越重要. ...
- Win10+Ubuntu 二三事
拯救者R720,反反复复弄了不少次,记录一下有用的blog 卸载 http://www.cnblogs.com/xia-Autumn/p/6294055.html https://blog.csdn. ...
- 一个封装不错的 TcpClient 类
using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading; nam ...
- quepy
A python framework to transform natural language questions to queries in a database query language. ...
- Aizu2224 Save your cats(最大生成树)
https://vjudge.net/problem/Aizu-2224 场景嵌入得很好,如果不是再最小生成树专题里,我可能就想不到解法了. 对所有的边(栅栏)求最大生成树,剩下来的长度即解(也就是需 ...
- 顺序栈的基本操作中Push压入后的- S.top = S.base + S.stacksize; 作用
#include <stdio.h> #include <malloc.h> #define TRUE 1 #define OK 1 #define ERROR 0 #defi ...