Python progress - 文本进度条

https://pypi.org/project/progress/
https://github.com/verigak/progress

Project description

Easy progress reporting for Python

Bars

There are 7 progress bars to choose from:

  • Bar
  • ChargingBar
  • FillingSquaresBar
  • FillingCirclesBar
  • IncrementalBar
  • PixelBar
  • ShadyBar

To use them, just call next to advance and finish to finish:

from progress.bar import Barbar = Bar('Processing', max=20)
for i in range(20):# Do some workbar.next()
bar.finish()

or use any bar of this class as a context manager:

from progress.bar import Barwith Bar('Processing', max=20) as bar:for i in range(20):# Do some workbar.next()

The result will be a bar like the following:

strong@foreverstrong:~/demo_workspace/progress_bar$ python progress_bar_v2.py
Processing |################################| 20/20
strong@foreverstrong:~/demo_workspace/progress_bar$ python progress_bar_v2.py
Processing |################################| 20/20
strong@foreverstrong:~/demo_workspace/progress_bar$

To simplify the common case where the work is done in an iterator, you can
use the iter method:

    for i in Bar('Processing').iter(it):# Do some work

Progress bars are very customizable, you can change their width, their fill
character, their suffix and more:

    bar = Bar('Loading', fill='@', suffix='%(percent)d%%')

This will produce a bar like the following:

    Loading |@@@@@@@@@@@@@                   | 42%

You can use a number of template arguments in message and suffix:

Name Value
index current value
max maximum value
remaining max - index
progress index / max
percent progress * 100
avg simple moving average time per item (in seconds)
elapsed elapsed time in seconds
elapsed_td elapsed as a timedelta (useful for printing as a string)
eta avg * remaining
eta_td eta as a timedelta (useful for printing as a string)

Instead of passing all configuration options on instatiation, you can create
your custom subclass:

    class FancyBar(Bar):message = 'Loading'fill = '*'suffix = '%(percent).1f%% - %(eta)ds'

You can also override any of the arguments or create your own:

    class SlowBar(Bar):suffix = '%(remaining_hours)d hours remaining'@propertydef remaining_hours(self):return self.eta // 3600

Spinners

For actions with an unknown number of steps you can use a spinner:

    from progress.spinner import Spinnerspinner = Spinner('Loading ')while state != 'FINISHED':# Do some workspinner.next()

There are 5 predefined spinners:

  • Spinner
  • PieSpinner
  • MoonSpinner
  • LineSpinner
  • PixelSpinner
spinner ['spɪnə]:n. 纺纱机,纺纱工人,旋床工人,旋式诱饵
override [əʊvə'raɪd]:vt. 推翻,不顾,践踏 n. 代理佣金

Installation

pip install progress
strong@foreverstrong:~$ pip install progress
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.warnings.warn(warning, RequestsDependencyWarning)
Collecting progressDownloading https://files.pythonhosted.org/packages/38/ef/2e887b3d2b248916fc2121889ce68af8a16aaddbe82f9ae6533c24ff0d2b/progress-1.5.tar.gz
Building wheels for collected packages: progressRunning setup.py bdist_wheel for progress ... doneStored in directory: /home/strong/.cache/pip/wheels/6c/c8/80/32a294e3041f006c661838c05a411c7b7ffc60ff939d14e116
Successfully built progress
Installing collected packages: progress
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/progress'
Consider using the `--user` option or check the permissions.You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$
strong@foreverstrong:~$ sudo pip install progress
[sudo] password for strong:
Sorry, try again.
[sudo] password for strong:
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/strong/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting progress
Installing collected packages: progress
Successfully installed progress-1.5
strong@foreverstrong:~$
strong@foreverstrong:~$ sudo pip3 install progress
[sudo] password for strong:
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/strong/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting progressDownloading https://files.pythonhosted.org/packages/38/ef/2e887b3d2b248916fc2121889ce68af8a16aaddbe82f9ae6533c24ff0d2b/progress-1.5.tar.gz
Installing collected packages: progressRunning setup.py install for progress ... done
Successfully installed progress-1.5
You are using pip version 8.1.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$

test_progress.py

#!/usr/bin/env pythonfrom __future__ import print_functionimport random
import timefrom progress.bar import (Bar, ChargingBar, FillingSquaresBar,FillingCirclesBar, IncrementalBar, PixelBar,ShadyBar)
from progress.spinner import (Spinner, PieSpinner, MoonSpinner, LineSpinner,PixelSpinner)
from progress.counter import Counter, Countdown, Stack, Piedef sleep():t = 0.01t += t * random.uniform(-0.1, 0.1)  # Add some variancetime.sleep(t)for bar_cls in (Bar, ChargingBar, FillingSquaresBar, FillingCirclesBar):suffix = '%(index)d/%(max)d [%(elapsed)d / %(eta)d / %(eta_td)s]'bar = bar_cls(bar_cls.__name__, suffix=suffix)for i in bar.iter(range(200)):sleep()for bar_cls in (IncrementalBar, PixelBar, ShadyBar):suffix = '%(percent)d%% [%(elapsed_td)s / %(eta)d / %(eta_td)s]'with bar_cls(bar_cls.__name__, suffix=suffix, max=200) as bar:for i in range(200):bar.next()sleep()for spin in (Spinner, PieSpinner, MoonSpinner, LineSpinner, PixelSpinner):for i in spin(spin.__name__ + ' ').iter(range(100)):sleep()for singleton in (Counter, Countdown, Stack, Pie):for i in singleton(singleton.__name__ + ' ').iter(range(100)):sleep()bar = IncrementalBar('Random', suffix='%(index)d')
for i in range(100):bar.goto(random.randint(0, 100))sleep()
bar.finish()
strong@foreverstrong:~/demo_workspace$ git clone https://github.com/verigak/progress.git
Cloning into 'progress'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 240 (delta 3), reused 9 (delta 2), pack-reused 230
Receiving objects: 100% (240/240), 646.83 KiB | 11.00 KiB/s, done.
Resolving deltas: 100% (143/143), done.
Checking connectivity... done.
strong@foreverstrong:~/demo_workspace$
strong@foreverstrong:~/demo_workspace$ cd progress
strong@foreverstrong:~/demo_workspace/progress$ python test_progress.py
Bar |################################| 200/200 [2 / 0 / 0:00:00]
ChargingBar ████████████████████████████████ 200/200 [2 / 0 / 0:00:00]
FillingSquaresBar ▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣ 200/200 [2 / 0 / 0:00:00]
FillingCirclesBar ◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ 200/200 [2 / 0 / 0:00:00]
IncrementalBar |████████████████████████████████| 100% [0:00:02 / 0 / 0:00:00]
PixelBar |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 100% [0:00:02 / 0 / 0:00:00]
ShadyBar |████████████████████████████████| 100% [0:00:02 / 0 / 0:00:00]
Spinner -
PieSpinner ◷
MoonSpinner ◑
LineSpinner ⎼
PixelSpinner ⡿
Counter 100
Countdown 0
Stack █
Pie ●
Random |███████████████████▌            | 61
strong@foreverstrong:~/demo_workspace/progress$

Python progress - 文本进度条相关推荐

  1. Python实现 文本进度条展示(嵩天老师)

    示例4:文本进度条 输出要求: -采用字符串方式打印文本进度条 -进度条需要能在一行中逐渐变化 代码:(不能动态刷新) #TextProBarV1.py import time scale=10 pr ...

  2. [Python] 实现文本进度条

    目录 简单的开始 单行动态刷新 带刷新的文本进度条 简单的开始 进度条是计算机处理任务或执行软件中常用的增强用户体验的重要手段,它能度条功能.今天我们将利用 Python 字符串处理方法实现文本进度条 ...

  3. Python 之文本进度条

    看到进度条一点点逼近百分之百,是不是很有成就感?! 下面我们就借助 python 来实现它. 为了能够更直观,我们姑且赋予开始和结束提示: #文本进度条import timescale=10print ...

  4. 【Python】文本进度条

    1.0代码: import time#引入time库 scale=10#文本进度条宽度 print("------执行开始------") for i in range(scale ...

  5. python制作文本进度条

    代码如下: import time scale=20 print("执行开始".center(scale,'-')) start=time.perf_counter() for i ...

  6. 用python编写文本进度条

    import time scale=50 print('执行开始'.center(scale//2,'-')) start=time.perf_counter() for i in range(sca ...

  7. 6行Python代码实现进度条效果(Progress、tqdm、alive-progress​​​​​​​和PySimpleGUI库)

    目录 1.Progress库 2.tqdm库 3.alive-progress库 4.PySimpleGUI库 在项目开发过程中加载.启动.下载项目难免会用到进度条,如何使用Python实现进度条呢? ...

  8. python文本进度条94页_Python学习笔记 | 实例4:文本进度条

    本文为中国大学MOOC<Python语言程序设计>课程学习笔记,课程主讲:嵩天老师,练习平台:Python123,参考教材:<Python语言程序设计基础> 文本进度条-简单的 ...

  9. Python项目实践:文本进度条

    文本进度条 采用字符串方式打印可以动态变化的文本进度条 进度条需要能在一行中逐渐变化 采用sleep()函数模拟一个持续的进度 版本一:简单的开始 # TextProBarV1.py import t ...

最新文章

  1. 升级在即,BU发布新版本并将Mempool未确认交易限制增加到500
  2. 为什么集群要奇数_面试系列 redis数据删除amp;集群
  3. Weblogic下创建JMS消息服务
  4. 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载...
  5. Oracle案例:一次非常艰难的drop多个PDB的恢复
  6. html 进度条roll,js实现增加数字显示的环形进度条效果
  7. C# 6.0 的新语法特性
  8. SlickEdit介绍
  9. QT+VS开发界面入门(qt界面在VS2022实现自动生成槽函数)
  10. 3D打印无人机等无人设备4——solidworks逆向建模编辑stl打印文件
  11. Vijos 3764 牛奶题
  12. java数据结构与算法总结(二十四)--RoaringBitmap数据结构及原理
  13. 【程序员段子】10个让你笑爆肚皮的程序员段子,不好笑算我输(生活太苦,不如经常来点儿甜~)
  14. 2023 USAMO(美国数学奥林匹克)试题答案解析
  15. 二叉树--二叉平衡树
  16. shell 补齐路径_Linux中10个有用的命令行补全例子
  17. 在线考试防作弊js代码
  18. 天语W700 adb驱动解决
  19. 静态网络与动态网络的区别(简单易懂)
  20. 在网络隔离下实现文件传输交换,你的方式真的安全吗?

热门文章

  1. springfox源码_重新认识Swagger和Springfox
  2. 五天入门SpringBoot(1)—Java SpringBoot 基础--helloworld,15分钟超快速入门
  3. 【Hive】json解析函数get_json_object
  4. 数位DP入门+数位DP模板
  5. ORA-00322,ORA-00312 排错
  6. 列举计算机组装所需的各个硬件,计算机组装与维修期中考试.doc
  7. 十三、 封装、继承和多态
  8. 网页劫持广告问题解决
  9. 零基础学习CSS---05.CSS背景属性详解
  10. TypeScript零基础入门之背景介绍和环境安装