i wish to improve my Progressbar in Python
from __future__ import division
import sys
import time
class Progress(object):
def __init__(self, maxval):
self._seen = 0.0
self._pct = 0
self.maxval = maxval
def update(self, value):
self._seen = value
pct = int((self._seen / self.maxval) * 100.0)
if self._pct != pct:
sys.stderr.write("|%-100s| %d%%" % (u"\u2588"*pct, pct) + '\n')
sys.stdout.flush()
self._pct = pct
def start(self):
pct = int((0.0 / self.maxval) * 100.0)
sys.stdout.write("|%-100s| %d%%" % (u"\u2588"*pct, pct) + '\n')
sys.stdout.flush()
def finish(self):
pct = int((self.maxval / self.maxval) * 100.0)
sys.stdout.write("|%-100s| %d%%" % (u"\u2588"*pct, pct) + '\n')
sys.stdout.flush()
toolbar_width = 300
pbar = Progress(toolbar_width)
pbar.start()
for i in xrange(toolbar_width):
time.sleep(0.1) # do real work here
pbar.update(i)
pbar.finish()