python 第三方進度條模組
阿新 • • 發佈:2021-07-05
不論你在什麼時候開始,重要的是開始之後就不要停止。 不論你在什麼時候結束,重要的是結束之後就不要悔恨。#! /usr/bin/env python # -*- coding: utf-8 -*-# # ------------------------------------------------------------------------------- # Name: demo01 # Author: yunhgu # Date: 2021/7/5 10:19 # Description: # ------------------------------------------------------------------------------- from time import sleep from tqdm import tqdm from progress.bar import IncrementalBar from alive_progress import alive_bar # 這裡同樣的,tqdm就是這個進度條最常用的一個方法 # 裡面存一個可迭代物件 def process_bar(): for i in tqdm(range(1, 500)): # 模擬你的任務 sleep(0.01) sleep(0.5) def process_bar01(): mylist = [1, 2, 3, 4, 5, 6, 7, 8] bar = IncrementalBar('Countdown', max=len(mylist)) for item in mylist: bar.next() sleep(1) def process_bar02(): # retrieve your set of items items = range(1000) # declare your expected total with alive_bar(len(items)) as bar: # iterate as usual for item in items: # process each item bar() sleep(0.1) if __name__ == '__main__': process_bar() # process_bar01() # process_bar02()