Using tqdm and rich as the fixed path and target of Python algorithm code to realize the progress bar

DechinPhy 2021-01-21 20:15:45
using tqdm rich fixed path


Applicable scenario

In the presence of fixed length algorithms, the process of algorithm execution can be visualized , For example, traversing a fixed length array , It is a kind of scene suitable for visualization with progress bar . And some conditional cycles , such as while loop , It is not necessarily suitable to use the progress bar to visualize the execution process of the algorithm , A typical scenario is a self consistent optimization algorithm .

tqdm How to use progress bar and its effect

It's also very easy to call methods , We just need to put our usual range Replace function with tqdm The built-in trange that will do .

# test_tqdm.py
from tqdm import trange
import time
for i in trange(10):
time.sleep(1)

Here is a display scenario for running the intermediate process

[dechin@dechin-manjaro progressbar]$ python3 test_tqdm.py
40%|████████████████ | 4/10 [00:04<00:06, 1.00s/it]

By multiple references trange, It can also print multiple progress bars , But here, if the number of the first floor is large , It can cause the screen output to be too complex :

# test_tqdm.py
from tqdm import trange
import time
for i in trange(10):
for j in trange(10):
time.sleep(0.1)

Here's the output from the execution :

[dechin@dechin-20n2s01200 progressbar]$ python3 test_tqdm.py
100%|███████████████████████████████████████| 10/10 [00:01<00:00, 9.88it/s]
100%|███████████████████████████████████████| 10/10 [00:01<00:00, 9.88it/s]
100%|███████████████████████████████████████| 10/10 [00:01<00:00, 9.88it/s]
30%|████████████ | 3/10 [00:03<00:07, 1.01s/it]

rich How to use progress bar and its effect

The method used is similar to tqdm Some of them are similar , Also called directly rich Medium track Yes range Function :

# test_rich.py
from rich.progress import track
import time
for i in track(range(15)):
time.sleep(1)

With simple tqdm The difference is ,rich Support a wide range of colors , The execution of the paste below shows , It's actually colored :

[dechin@dechin-manjaro progressbar]$ python3 test_rich.py
Working... ━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 27% 0:00:12

Copyright notice

The first link to this article is :https://www.cnblogs.com/dechinphy/p/progress-bar.html
author ID:DechinPhy
For more original articles, please refer to :https://www.cnblogs.com/dechinphy/

版权声明
本文为[DechinPhy]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210121201501071h.html

  1. Centos7 installing Python 3.8
  2. Centos7 installing Python 3.8
  3. Django——图书管理系统(六)
  4. Django——图书管理系统(五)
  5. Django -- library management system (6)
  6. Django -- library management system (5)
  7. python批量插入数据小脚本
  8. Python batch insert data script
  9. ZoomEye-python 使用指南
  10. Zoomeye Python User's Guide
  11. 用Python写代码,一分钟搞定一天工作量,同事直呼:好家伙 - 知乎
  12. Using Python to write code, one minute to complete a day's workload, colleagues call: good guy - Zhihu
  13. Python 上的可视化库——PyG2Plot
  14. Pyg2plot: a visualization library on Python
  15. Python 上的可视化库——PyG2Plot
  16. Python实用代码-无限级分类树状结构生成算法
  17. Pyg2plot: a visualization library on Python
  18. Python utility code - infinite classification tree structure generation algorithm
  19. 奇技淫巧,还是正统功夫?Python推导式最全用法
  20. Pandas 的这个知识点,估计 80% 的人都得挂!
  21. 前后端分离有什么了不起,手把手教你用Python爬下来!
  22. 在 Azure 上执行一些简单的 python 工作
  23. 推荐 :利用Python的混合集成机器学习(附链接)
  24. Cunning or orthodox Kung Fu? The most complete usage of Python derivation
  25. It's estimated that 80% of pandas people have to hang up!
  26. What's so great about the separation of front and rear ends? Hand in hand teach you to climb down with Python!
  27. Doing some simple Python work on azure
  28. Recommendation: hybrid integrated machine learning using python (link attached)
  29. Learning PPO algorithm programming from scratch (Python version)
  30. Python OpenCV 图片模糊操作 blur 与 medianBlur
  31. Python OpenCV image blur operation blur and mediablur
  32. 成功解决cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: err
  33. Cv2.error solved successfully: opencv (4.1.2) C:: (projects / opencv Python / opencv modules / imgproc / SRC)\ color.cpp:182 : err
  34. Python 中使用 virtualenv 管理虚拟环境
  35. Using virtualenv to manage virtual environment in Python
  36. 如何使用Python执行系统命令?Python学习教程!
  37. How to use Python to execute system commands? Python tutorial!
  38. 快速掌握Python中的循环技术
  39. Quickly grasp the loop technology in Python
  40. Python主流Web框架之Tornado
  41. appium+python自动化63-使用Uiautomator2报错问题解决
  42. Tornado: the mainstream Python Web Framework
  43. Appium + Python automation 63 - using uiautomator2 to solve the problem of error reporting
  44. 爬虫+django,打造个性化API接口
  45. Crawler + Django to create personalized API interface
  46. 爬虫+django,打造个性化API接口
  47. Crawler + Django to create personalized API interface
  48. C、C++、Java、PHP、Python主要应用在哪里方面?
  49. C. Where are the main applications of C + +, Java, PHP and python?
  50. Python 无限级分类树状结构生成算法 「实用代码」
  51. Python infinite classification tree structure generation algorithm "practical code"
  52. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
  53. [azure storage service] Python module( azure.cosmosdb.table )Direct operation example of storage account table
  54. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
  55. [azure storage service] Python module( azure.cosmosdb.table )Direct operation example of storage account table
  56. openpose c++ 配置教程 + python api
  57. Openpose C + + configuration tutorial + Python API
  58. PYTHON爬虫实战_垃圾佬闲鱼爬虫转转爬虫数据整合自用二手急速响应捡垃圾平台_3(附源码持续更新)
  59. 使用python javaSerializationTools模块拼接生成 8u20 Gadget
  60. 萌新入门之python基础语法