易于使用的ETA计算和进度条库。
etaprogress的Python项目详细描述
在您的控制台应用程序中绘制带有颜色空间、显示速率和ETA的进度条。埃塔图书馆是自己的 类,以便它可以在其他非控制台应用程序中使用。用简单线性回归计算etas。
此库支持已定义和未定义的进度条。未定义的进度条是那些没有 “总尺寸”。类似于wget下载文件大小未知的文件。因此,未定义进度条 没有百分比,也没有预计到达时间。定义的进度条是带有百分比和ETA的常用进度条。
- Linux和OS X支持Python 2.6、2.7、3.3和3.4。
- 在windows上支持python 2.7、3.3和3.4(python的32位和64位版本)。
在WindowsXP和Windows10技术预览版上测试。
快速启动
安装:
pip install etaprogress
示例实现
示例的源代码:example.py, example_colors.py, 以及example_wget.py
用法
如果您只需要一个带有eta的进度条,那么只需要在etaprogress.progress模块中导入一个类。 只需将进度条本身转换为字符串或打印实例。
简单用法
importtimefrometaprogress.progressimportProgressBartotal=5bar=ProgressBar(total,max_width=40)foriinrange(total+1):bar.numerator=iprintbartime.sleep(1)
0% (0/5) [ ] eta --:-- - 20% (1/5) [### ] eta 00:05 \ 40% (2/5) [###### ] eta 00:04 | 60% (3/5) [######### ] eta 00:03 / 80% (4/5) [############ ] eta 00:02 - 100% (5/5) [###############] eta 00:00 \
当然这不是一个很好的进度条动画。这里有一个更好的print_function:
from__future__importprint_functionimportsysimporttimefrometaprogress.progressimportProgressBartotal=5bar=ProgressBar(total,max_width=40)foriinrange(total+1):bar.numerator=iprint(bar,end='\r')sys.stdout.flush()time.sleep(1)print()
100% (5/5) [###############] eta 00:00 \
终端颜色支持
使用colorclass支持颜色。看一看 example_colors.py关于如何实现 彩色进度条。您可能需要将progressbar类(甚至baseprogressbar)的一个子类进行子类化以添加颜色。 到进度条的每个角落。
类属性
有五个不同的进度条类具有视觉差异:
- ProgressBar–一个简单的进度条。
- ProgressBarBits–类似于ProgressBar,但将数字转换为位、千位等。
- ProgressBarBytes–类似于ProgressBar,但将数字转换为字节、千字节(kibibytes)等。
- ProgressBarWget–一个进度条,看起来像gnuwget应用程序中的进度条。
- ProgressBarYum–一个进度条,看起来像centos/rhel 7yum实用程序中的进度条。
Name | Description/Notes |
---|---|
^{tt12}$ | Limit number of characters shown (by default the full progress bar takes up the entire terminal width). |
^{tt13}$ | Calculate and cache the ETA string after this many numerator setting iteration. Default is every iter. |
^{tt14}$ | For undefined progress bars this indicates that the progress has completed. |
^{tt15}$ | ‘ProgressBarYum’ only. The string to display before the progress bar. Limited to whatever space is available in the terminal. |
类属性
Name | Description/Notes |
---|---|
^{tt16}$ | Returns the denominator of the progress bars. The same value provided when instantiating. |
^{tt17}$ | Returns True if the progress has completed. |
^{tt18}$ | Read/write. Returns the numerator as an integer or sets a new numerator. When setting a numerator it must be equal to or greater than the previous one. |
^{tt19}$ | Returns the percent as a float. |
^{tt20}$ | Returns the rate of the progress as a float. |
^{tt21}$ | Return True if the progress bar is undefined. |
更改日志
1.1.1
- 修复了损坏的setup.py文件。
1.1.0
- 添加了Windows支持。
1.0.0
- 初次发布。