Python output progress bar on the console, python progress bar
This article describes how to output a progress bar in the python console. Share it with you for your reference. The specific implementation method is as follows:
The progress bar is as follows:
| ########################## ------------------- | 59 percent done
The Code is as follows:
Class ProgressBar (): def _ init _ (self, width = 50): self. pointer = 0 self. width = width def _ call _ (self, x): # x in percent self. pointer = int (self. width * (x/100.0) return "|" + "#" * self. pointer + "-" * (self. width-self.pointer) + \ "| \ n % d percent done" % int (x)
Test function (for windows system, change "clear" into "CLS "):
If _ name _ = '_ main _': import time, OS pb = ProgressBar () for I in range (101): OS. system ('clear') print pb (I) time. sleep (0.1)
I hope this article will help you with Python programming.