python使用progressbar显示进度条
2024-08-26 18:56:55
progressbar安装:
pip install progressbar
用法一
# -*- coding=utf-8 -*-
import time
from progressbar import *
total = 1000
def dosomework():
time.sleep(0.01)
progress = ProgressBar()
for i in progress(range(1000)):
dosomework()
显示效果:
5% |### |
100% |#########################################################################|
用法二
# -*- coding=utf-8 -*-
from __future__ import division
import sys, time
from progressbar import *
total = 1000
def dosomework():
time.sleep(0.01)
pbar = ProgressBar().start()
for i in range(1000):
pbar.update(int((i / (total - 1)) * 100))
dosomework()
pbar.finish()
显示效果:
39% |############################## |
100% |#############################################################################|
用法三
# -*- coding=utf-8 -*-
import time
from progressbar import *
total = 1000
def dosomework():
time.sleep(0.01)
widgets = ['Progress: ',Percentage(), ' ', Bar('#'),' ', Timer(),
' ', ETA(), ' ', FileTransferSpeed()]
pbar = ProgressBar(widgets=widgets, maxval=10*total).start()
for i in range(total):
# do something
pbar.update(10 * i + 1)
dosomework()
pbar.finish()
显示效果:
Progress: 3% |### | Elapsed Time: 0:00:15 ETA: 0:09:02 919.67 B/s
Progress: 100% |###################################################################################| Elapsed Time: 0:10:10 Time: 0:10:10 917.42 B/s
widgets可选参数含义:
- 'Progress: ' :设置进度条前显示的文字
- Percentage() :显示百分比
- Bar('#') : 设置进度条形状
- ETA() : 显示预计剩余时间
- Timer() :显示已用时间
最新文章
- 如何给GridView添加网格
- ppp数据帧的格式
- 我是如何用Go语言搭建自己的博客的
- MVC5 + EF6 + Bootstrap3 (14) 分部视图PartialView
- Runtime运行时的那点事儿
- poj3692_Kindergarten
- 设置用户sudo -s拥有root权限
- Hibernate四 批量处理
- zsh中home键失灵问题
- 【转】Python操作MongoDB数据库
- ispriter自动构建css-sprite
- jzoj5925
- SQL Server 数据库存储过程实例
- NGUI诡异的drawCall
- Servlet.service() for servlet UserServlet threw exception java.lang.NullPointerException 空指针异常
- asp.net mvc 上传图片 摘自mvc 高级编程第311页
- iOS开发~制作同时支持armv7,armv7s,arm64,i386,x86_64的静态库.a以及 FrameWork 的创建
- Linux系统下安装Redis和Redis集群配置
- Vue脚手架开发使用sass
- LocalReport Print with C# C#打印RDLC
热门文章
- 树梅派配置ad-hoc网络
- mybatis中的懒加载
- Android studio 运行模拟器报:Application Installation Failed
- 决策树的剪枝,分类回归树CART
- Learning Perl 第九章习题第二题
- 数据库访问辅助类SqlHelper
- tp5---auth权限搭建2
- thinkphp3.2.3 + nginx 配置二级域名
- Python模块学习之解决selenium的“can't access dead object”错误
- Java String类为什么不可变?