Example of cascading progress information that Python implements for easy use

Source: Internet
Author: User

This article mainly introduces the implementation of Python to facilitate the use of cascading progress information, example analysis of Python display cascading progress information related skills, very practical value, the need for friends can refer to the

The examples in this article describe how Python implements the cascading progress information that is convenient to use. Share to everyone for your reference. The implementation methods are as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58-59 60 class Stepedprogress: '" to facilitate the display of progress of the Cascade progress information. ' 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 # Recalculate progress ratio, prevent initialization value not add up to 1 w = 0.0 for P in self.stockpercent:w + = p for i in range (0, Len (stockpercent)): stockpercent[i] = stockpercent[i]/w # initialization Child Progress If Len (stockpercent) = = 1:self.subprogress = None else:for p in Self.stockPercent:self.subProgress.append (Stepedprogre SS (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 i s not None:self.parentProgress.notifyParentProgress (percent, info) else:print self.info[:77].ljust (, '. '), "[%0.1f% %] "%self.percent if __name__ = =" __main__ ": s = stepedprogress ([a)] s.notifyprogress (" AAA ") S1 = s.subprogress (0) S1.notifyprogress (M, ' bbb ') s3 = s.subprogress (1) s3 = Stepedprogress ([1, 1], parentprogress=s3.parentprogress) #级联子进度 s 3.notifyProgress (M, ' ddd ') s4 = s3.subprogress (0) s4.notifyprogress (+, ' eee ') s5 = s3.subprogress (1) s5.notifyprogress (+, ' FFF ')

Output results:

Aaa............................................................................. [10%]

Bbb............................................................................. [30%]

Ddd............................................................................. [68%]

Eee ..... ....... ....... ....... ..... ...... ... ............. ...... ....... ....... ... [70%]

FFF ..... ....... ....... ....... ..... ...... ... ............. ...... ....... ....... ... [90%]

I hope this article will help you with your Python programming.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.