How to realize the python text progress bar
This article introduces the relevant knowledge of "how to realize the python text progress bar". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1, at the beginning (which may be very low) import timescale=10print ("- execution start -") for i in range (scale+1): a starting execution starting I baked train.execution * (scale-i) c = (i/scale) * 100print ("{: ^ 3.0f}% [{}-> {}]" .format (cMagna)) time.sleep (0.1) print ("- end of execution--")''2. One-line disappearance
Must be implemented on the cmd command line because idle disables the function of\ r
Compare
1.\ r the function is to return the cursor to the beginning of the segment before output and then output it again.
2. The function of end = "" is not to wrap the cursor after this line.
Import timefor i in range: # idle actually blocks the function print ("\ r {: 3}%" .format (I), end= "") time.sleep (0.1) 3. One-line disappearance after optimization
(also must run on cmd, ditto)
Import timescale=50print ("execution start" .center (scale//2, "-")) start=time.perf_counter () for i in range (scale+1): a starting cycle for others, such as baccalaureate. Scale-i * (scale-i) c = (i/scale) * 100 dur=time.perf_counter ()-start print ("\ r {: ^ 3.0f}% [{}-> {}] {: .2f} s" .format End='') time.sleep (0.1) print ("end of execution" .center (scale//2, "-")) "how to implement the python text progress bar" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!