Python使用progressbar模塊實現(xiàn)的顯示進度條功能
本文實例講述了Python使用progressbar模塊實現(xiàn)的顯示進度條功能。分享給大家供大家參考,具體如下:
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可選參數(shù)含義:
'Progress: ' :設(shè)置進度條前顯示的文字
Percentage() :顯示百分比
Bar('#') : 設(shè)置進度條形狀
ETA() : 顯示預(yù)計剩余時間
Timer() :顯示已用時間
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)學(xué)運算技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
Python中使用print函數(shù)進行不換行打印問題
這篇文章主要介紹了Python中使用print函數(shù)進行不換行打印問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02Python坐標(biāo)線性插值應(yīng)用實現(xiàn)
這篇文章主要介紹了Python坐標(biāo)線性插值應(yīng)用實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11Python?asyncore?socket客戶端開發(fā)基本使用教程
asyncore庫是python的一個標(biāo)準(zhǔn)庫,提供了以異步的方式寫入套接字服務(wù)的客戶端和服務(wù)器的基礎(chǔ)結(jié)構(gòu),這篇文章主要介紹了Python?asyncore?socket客戶端開發(fā)基本使用,需要的朋友可以參考下2022-12-12python字符串切割:str.split()與re.split()的對比分析
今天小編就為大家分享一篇python字符串切割:str.split()與re.split()的對比分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07Python中plt.plot()、plt.scatter()和plt.legend函數(shù)的用法示例
今天想要用matplotlib中的plt函數(shù)繪制圖表,將多個數(shù)據(jù)曲線在一個圖表中進行呈現(xiàn),下面這篇文章主要給大家介紹了關(guān)于Python中plt.plot()、plt.scatter()和plt.legend函數(shù)用法的相關(guān)資料,需要的朋友可以參考下2022-03-03