Often use sleep time,
Started using sleepxxx to show
This is still not intuitive.
The effect is as follows:
==================================sleep s===================================00:00 [================== ============================================== ]
defSleep_time (Duration, width=80): Msg="SLEEP%s S"%(duration) left= (Width-len (msg))//2Print("\ r \%s%s%s\r\n"% (MK_HR ("=", left-1), Msg,mk_hr ("=", width-left-len (msg)))) CNT=0 while(CNT < duration + 1): Sys.stdout.write ("\r%s\r"%(Progress_bar (Duration, cnt, width)) Sys.stdout.flush () Time.sleep (1) CNT+ = 1Print("\ r \ n")defProgress_bar (Total, CNT, width=80): defprogress_print (total, Width, cnt): Left= CNT * width//Total cent="=" ifCNT% 2 = = 0Else " " ifCNT = =total:cent="" returnMK_HR ("=", left) + cent + mk_hr ("-", width-left-1) msg="ETA:"ucnt= total-CNTifTotal < 3600: Msg="%s%s"% (MSG,"%02d:%02d"% (ucnt//60,ucnt%60)) Else: Msg="%s%s"% (MSG,"%02d:%02d:%02d"% (ucnt//3600, (ucnt-(ucnt//3600) *3600)//60,ucnt%60)) left=len (msg)ifLeft > Width-1: returnmsgElse: return "%s [%s]"% (msg, Progress_print (Total, width-left-5, CNT))
defmk_hr (fill, width): result="" forIinchxrange (int (width)): Result+=FillreturnResult
Python progress bar