本文实例讲述了Python实现方便使用的级联进度信息的方法。分享给大家供大家参考。具体实现方法如下:
class StepedProgress: '''方便显示进度的级联进度信息。 ''' 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 # 重新计算进度比,防止初始化时的值加起来不是1 w = 0.0 for p in self.stockPercent: w += p for i in range(0, len(stockPercent)): stockPercent[i] = stockPercent[i]/w # 初始化子进度 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) #级联子进度 s3.notifyProgress(20, 'ddd') s4 = s3.subprogress(0) s4.notifyProgress(50, 'eee') s5 = s3.subprogress(1) s5.notifyProgress(50, 'fff')
输出结果:
aaa............................................................................. [10.0%]
bbb............................................................................. [30.0%]
ddd............................................................................. [68.0%]
eee............................................................................. [70.0%]
fff............................................................................. [90.0%]
希望本文所述对大家的Python程序设计有所帮助。
Python,级联,进度信息
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】