在终端中显示加载条的库。
loadingbar的Python项目详细描述
python加载栏
python模块在终端窗口中显示一个不错的加载条。
安装
转到模块目录并运行:
$ pip install setup.py
或:
$ python3 setup.py install
开始
有3种不同的加载条:
- 标准加载杆
- 加载尺寸、速度和剩余时间的加载条
- 带有以上信息的加载条和一条自定义消息(用于显示详细的加载条)
选项1
没有任何其他信息的标准加载条。
importloadingtotal_file_size=1000# Create a loading bar object with total_file_size in byteslb=loadingbar.LoadingBar(total_file_size)# For every piece of fileforchunkinfile:# Update the loading bar with the len of new datalg.update(len(chunk))# When finished, display a 100% loading barlg.done()
选项2
标准加载条,包含下载的大小、速度、预计到达时间等信息。
importloadingtotal_file_size=1000lb=loadingbar.InfoLoadingBar(total_file_size)# Run as above
选项3
这个特殊的InternetLoadingBar
通过计算整体平均时间而不是瞬时速度来平滑速度计算。
importloadingtotal_file_size=1000lb=loadingbar.InternetLoadingBar(total_file_size)# Run as above
选项4
显示消息的加载栏,例如下载的文件名。两个选项:
loadingbar.MessageLoadingBar
loadingbar.VerboseLoadingBar
importloadingtotal_file_size=1000lb=loadingbar.VerboseLoadingBar(total_file_size)# For every piece of fileforchunkinfile:# Update the loading bar with the len of new datalg.update(len(chunk),"Message to be displayed, such as filename, etc.")# When finished, display a 100% loading barlg.done()
选项5
在加载栏后添加百分比。
loadingbar.PercentageLoadingBar(tot_size)
loadingbar.PercentageInfoLoadingBar(tot_size)
选项6
在加载栏后添加百分比。
loadingbar.PercentageBeforeLoadingBar(tot_size)
loadingbar.PercentageBeforeLoadingBarAndInfo(tot_size)
定制
如果需要新的自定义加载条,可以通过从loading bar类或抽象类iloadingbar继承来实现新的加载条。 有关示例,请参见加载>;loading_bar.py。
许可证
麻省理工学院执照。 请随意使用、分享或改进它。