python使用progressbar顯示進度條

來源:互聯網
上載者:User

標籤:顯示   file   log   finish   speed   csdn   https   nsf   clipboard   

progressbar安裝:

[python] view plain copy 
  1. pip install progressbar  

 

用法一

[python] view plain copy 
  1. # -*- coding=utf-8 -*-  
  2.   
  3. import time  
  4. from progressbar import *  
  5.   
  6. total = 1000  
  7.   
  8. def dosomework():  
  9.     time.sleep(0.01)  
  10.   
  11. progress = ProgressBar()  
  12. for i in progress(range(1000)):  
  13.     dosomework()  

顯示效果:

[python] view plain copy 
  1. 5% |###                                                                      |  
  2. 100% |#########################################################################|  

 

用法二

[python] view plain copy 
  1. # -*- coding=utf-8 -*-  
  2.   
  3. from __future__ import division  
  4.   
  5. import sys, time  
  6. from progressbar import *  
  7.   
  8. total = 1000  
  9.   
  10. def dosomework():  
  11.     time.sleep(0.01)  
  12.   
  13. pbar = ProgressBar().start()  
  14. for i in range(1000):  
  15.     pbar.update(int((i / (total - 1)) * 100))  
  16.     dosomework()  
  17. pbar.finish()  

顯示效果:

[python] view plain copy 
  1. 39% |##############################                                               |  
  2. 100% |#############################################################################|  

 

用法三

[python] view plain copy 
  1. # -*- coding=utf-8 -*-  
  2.   
  3. import  time  
  4. from progressbar import *  
  5.   
  6. total = 1000  
  7.   
  8. def dosomework():  
  9.     time.sleep(0.01)  
  10.   
  11. widgets = [‘Progress: ‘,Percentage(), ‘ ‘, Bar(‘#‘),‘ ‘, Timer(),  
  12.            ‘ ‘, ETA(), ‘ ‘, FileTransferSpeed()]  
  13. pbar = ProgressBar(widgets=widgets, maxval=10*total).start()  
  14. for i in range(total):  
  15.     # do something  
  16.     pbar.update(10 * i + 1)  
  17.     dosomework()  
  18. pbar.finish()  

顯示效果:

[python] view plain copy 
  1. Progress:   3% |###                                                                                | Elapsed Time: 0:00:15 ETA: 0:09:02 919.67  B/s  
  2. Progress: 100% |###################################################################################| Elapsed Time: 0:10:10 Time: 0:10:10 917.42  B/s  

 

widgets選擇性參數含義:

    • ‘Progress: ‘ :設定進度條前顯示的文字
    • Percentage() :顯示百分比
    • Bar(‘#‘) : 設定進度條形狀
    • ETA() : 顯示預計剩餘時間
    • Timer() :顯示經過時間 

python使用progressbar顯示進度條

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.