PyPrind(Python Progress Indicator)
PyPrind (Python Progress Indicator)模块提供了一个进度条和一个百分比指示器对象,它允许您跟踪循环结构或其他迭代计算的进度。
典型的应用程序包括处理大数据集,以便在运行时对计算的进展提供直观的估计。
安装方法:
pip install pyprind
进度条指标:
import pyprind
import time
for progress in pyprind.prog_bar(range(20)):
time.sleep (1)显示: 0% [####################] 100% | ETA: 00:00:00
Total time elapsed: 00:00:10
Total time elapsed: 00:00:10
百分比指标:
import pyprind
import time
for progress in pyprind.prog_percent (range (20)):
time.sleep (1)显示: [100 %] Time elapsed: 00:00:20 | ETA: 00:00:00
Total time elapsed: 00:00:20
Total time elapsed: 00:00:20
先进的跟踪:
import pyprind
import time
bar = pyprind.ProgBar(30,monitor=True,title="job01")
for i in range(30):
time.sleep (0.5)
bar.update()
print(bar)显示: job01
0% [############################# ] 100% | ETA: 00:00:00Title: job01
0% [##############################] 100% | ETA: 00:00:00
Started: 01/18/2018 17:55:27
Total time elapsed: 00:00:15
Finished: 01/18/2018 17:55:42
Total time elapsed: 00:00:15
CPU %: 0.00
Memory %: 0.18
0% [############################# ] 100% | ETA: 00:00:00Title: job01
0% [##############################] 100% | ETA: 00:00:00
Started: 01/18/2018 17:55:27
Total time elapsed: 00:00:15
Finished: 01/18/2018 17:55:42
Total time elapsed: 00:00:15
CPU %: 0.00
Memory %: 0.18
可更改进度条显示符号:
bar = pyprind.ProgBar(30,monitor=True,title="job01",bar_char="-")显示: 0% [----------------------------- ] 100% | ETA: 00:00:00
Pyprind方法一览:
ProgBar:
class ProgBar(Prog):
"""
初始化一个允许可视化的进度条对象。
在标准输出屏幕上的迭代计算。
Parameters
----------
iterations : `int`
迭代计算的迭代次数。
track_time : `bool` (default = `True`)
当循环结束时打印经过的时间。
width : `int` (default = 30)
设置字符的进度条宽度。
stream : `int` (default = 2).
设置输出流。
以“1”为标准输出,“2”为 标准错误,或自定义流对象。
title : `str` (default = `''`).
为进度条设置标题。
monitor : `bool` (default = False)
监视CPU和内存使用情况,如果“True”(需要“psutil”包)。
"""
ProgPercent:
class ProgPercent(Prog):
"""
初始化一个允许可视化的进度条对象。
在标准输出屏幕上的迭代计算。
Parameters
----------
iterations : `int`
迭代计算的迭代次数。
track_time : `bool` (default = `True`)
当循环结束时打印经过的时间。
stream : `int` (default = 2).
设置输出流。
以“1”为标准输出,“2”为标准错误,或自定义流对象。
title : `str` (default = `''`).
设置百分比指示器的标题。
monitor : `bool` (default = False)
监视CPU和内存使用情况,如果“True”(需要“psutil”包)。
"""

PyPrind 模块提供了进度条和百分比指示器功能,适用于 Python 中的大数据集处理或长时间运行的任务,便于实时跟踪计算进度。本文介绍如何安装 PyPrind 并展示了多种使用示例。
1605

被折叠的 条评论
为什么被折叠?



