允许轻松创建进度条和文本
项目描述
允许轻松创建进度条和文本。
progress已经使用 Python 2.6、2.7、3.2、3.3 和 PyPy 进行了测试,目前至少需要 Python 2.6
安装:
注意: PyPI 已经包含一个进度条目,所以这个模块位于progress2。
您可以通过pip安装:
pip install progress2
或者,下载源文件并从下载目录运行以下命令:
python setup.py install
用法:
创建进度条:
>>> import progress
>>> bar = progress.ProgressBar("[{progress}] {percentage:.2f}% ({minutes}:{seconds})", width=30)
>>> bar.show()
[ ] 0.00% (0:0)>>>
>>> bar.update(26)
>>> bar.show()
[======> ] 26.00% (0:0)>>>
>>>
或者,您可以使用自动更新方法:
>>> bar.autoupdate(42) [===================> ] 68.00% (0:45)>>> >>>
创建ProgressText:
>>> text = progress.ProgressText("Searching: {progress}", "|/-\\", autoreset=True)
>>> text.show()
|>>>
>>> text.update(); text.show()
/>>>
>>> text.update(); text.show()
->>>
>>> text.update(); text.show()
\>>>
您可以提供自定义 args 和 kwargs 来显示和自动更新:
>>> bar = progress.ProgressBar("[{progress}] {key} {},{},{}")
>>> d = dict(key=33)
>>> l = range(3)
>>> bar.update(50)
>>> bar.show(*l, **d)
[=========> ] 33 0,1,2>>>
>>> bar.autoupdate(25, *l, **d)
[==============> ] 33 0,1,2>>>
>>>
有关更多示例,请参阅示例/目录。还有一些关于如何使用threading模块的例子。
实施说明:
由于大多数终端无法通过换行符或回车清除其输出缓冲区, 因此如果插入它们,进度将不起作用,例如progress.ProgressBar("{progress}\n{percentage}") 将不会从终端中清除。