国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現(xiàn)方便使用的級聯(lián)進度信息實例

2020-02-23 01:04:55
字體:
供稿:網(wǎng)友

本文實例講述了Python實現(xiàn)方便使用的級聯(lián)進度信息的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

class StepedProgress:  '''方便顯示進度的級聯(liá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    # 重新計算進度比,防止初始化時的值加起來不是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.percentif __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) #級聯(liá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%]

希望本文所述對大家的Python程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 泸定县| 浑源县| 阜阳市| 家居| 平阴县| 伊川县| 雅江县| 武夷山市| 兰西县| 巴塘县| 云和县| 济源市| 余干县| 怀宁县| 三原县| 蒙阴县| 松江区| 梧州市| 淮滨县| 开封市| 虎林市| 谢通门县| 嘉祥县| 鄂托克前旗| 喀喇沁旗| 金坛市| 信阳市| 象山县| 邓州市| 金溪县| 江西省| 沙田区| 宁海县| 东阿县| 株洲县| 澎湖县| 莒南县| 孝感市| 南华县| 朝阳市| 朝阳市|