Simple progress bar in Python

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) if __name__ == '__main__': import time, os pb = ProgressBar() for i in range(101): os.system('clear') print pb(i) time.sleep(0.1)
A "progress bar" that looks like:

|#############################---------------------|
99 percent done

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.