Advertisement
here2share

# console_progressbar.py

Apr 8th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # console_progressbar.py
  2.  
  3. import time, sys, os
  4. def clear(): os.system('cls||clear') ###ZZZ might be quite glitchy
  5.  
  6. class ProgressBar():
  7.     pointer = 0
  8.     width = 50
  9.  
  10.     def __call__(self,x):
  11.         # x in percent
  12.         self.pointer = int(self.width*(x/100.0))
  13.         progress = '\r > ' + chr(178)*self.pointer + ':'*(self.width-self.pointer)+\
  14.         " < %d Percent  " % int(x)
  15.        
  16.         #clear()
  17.         sys.stdout.write(progress)
  18.         sys.stdout.flush()
  19.  
  20. print
  21. pb = ProgressBar()
  22. for i in range(101):
  23.     pb(i)
  24.     time.sleep(0.1)
  25.  
  26. print "\n\n *** Task Now Complete ***"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement