Python實(shí)現(xiàn)方便使用的級(jí)聯(lián)進(jìn)度信息實(shí)例
本文實(shí)例講述了Python實(shí)現(xiàn)方便使用的級(jí)聯(lián)進(jìn)度信息的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
class StepedProgress:
'''方便顯示進(jìn)度的級(jí)聯(lián)進(jìn)度信息。
'''
def __init__(self, stockPercent=[1], parentProgress=None):
self.percent = 0
self.info = ''
self.subProgress = []
self.cur_running_process = 0
self.stockPercent = stockPercent
self.parentProgress = parentProgress
# 重新計(jì)算進(jìn)度比,防止初始化時(shí)的值加起來不是1
w = 0.0
for p in self.stockPercent:
w += p
for i in range(0, len(stockPercent)):
stockPercent[i] = stockPercent[i]/w
# 初始化子進(jìn)度
if len(stockPercent) == 1:
self.subProgress = None
else:
for p in self.stockPercent:
self.subProgress.append(StepedProgress(parentProgress=self))
def subprogress(self, index):
if index >= self.subcount():
return self.subProgress[self.subcount()-1]
elif index < self.cur_running_process:
return self.subProgress[self.cur_running_process]
else:
self.cur_running_process = index
return self.subProgress[index]
def subcount(self):
return len(self.subProgress)
def notifyParentProgress(self, percent, info=None):
new_percent = 0.0
for i in range(0, self.cur_running_process):
new_percent += self.stockPercent[i]
new_percent += percent/100.0 * self.stockPercent[self.cur_running_process]
new_percent *= 100.0
self.notifyProgress(new_percent, info)
def notifyProgress(self, percent, info=None):
if percent > self.percent:
self.percent = percent
if info is not None:
self.info = info
if self.parentProgress is not None:
self.parentProgress.notifyParentProgress(percent, info)
else:
print self.info[:77].ljust(80, '.'), "[%0.1f%%]"%self.percent
if __name__ == "__main__":
s = StepedProgress([60, 40])
s.notifyProgress(10, 'aaa')
s1 = s.subprogress(0)
s1.notifyProgress(50, 'bbb')
s3 = s.subprogress(1)
s3 = StepedProgress([1, 1], parentProgress=s3.parentProgress) #級(jí)聯(lián)子進(jìn)度
s3.notifyProgress(20, 'ddd')
s4 = s3.subprogress(0)
s4.notifyProgress(50, 'eee')
s5 = s3.subprogress(1)
s5.notifyProgress(50, 'fff')
輸出結(jié)果:
aaa............................................................................. [10.0%]
bbb............................................................................. [30.0%]
ddd............................................................................. [68.0%]
eee............................................................................. [70.0%]
fff............................................................................. [90.0%]
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Django中STATIC_ROOT和STATIC_URL及STATICFILES_DIRS淺析
這篇文章主要給大家介紹了關(guān)于Django中STATIC_ROOT和STATIC_URL及STATICFILES_DIRS的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧2018-05-05
Python利用正則表達(dá)式匹配并截取指定子串及去重的方法
這篇文章主要介紹了Python利用正則表達(dá)式匹配并截取指定子串及去重的方法,涉及Python正則表達(dá)式匹配及字符串截取操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
python數(shù)據(jù)結(jié)構(gòu)鏈表之單向鏈表(實(shí)例講解)
下面小編就為大家?guī)硪黄猵ython數(shù)據(jù)結(jié)構(gòu)鏈表之單向鏈表(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
如何利用Python將html轉(zhuǎn)為pdf、word文件
網(wǎng)絡(luò)上存在很多將HTML轉(zhuǎn)換為PDF的軟件和工具,但是大家都知道收費(fèi),所以下面這篇文章主要給大家介紹了關(guān)于如何利用Python將html轉(zhuǎn)為pdf、word文件的相關(guān)資料,文中通過示例代碼介紹介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
Django學(xué)習(xí)教程之靜態(tài)文件的調(diào)用詳解
這篇文章主要給大家介紹了關(guān)于Django學(xué)習(xí)教程之靜態(tài)文件調(diào)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05
python中sklearn庫predict及python sklearn linearmodel(
Scikit-learn(sklearn)是機(jī)器學(xué)習(xí)中常用的第三方模塊,對(duì)常用的機(jī)器學(xué)習(xí)方法進(jìn)行了封裝,包括回歸(Regression)、降維(Dimensionality Reduction)、分類(Classfication)、聚類(Clustering)等方法,今天小編給大家分享python中sklearn庫predict的問題,感興趣的朋友一起看看吧2024-02-02
python中playwright結(jié)合pytest執(zhí)行用例的實(shí)現(xiàn)
本文主要介紹了python中playwright結(jié)合pytest執(zhí)行用例的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12

