i wish to improve my Progressbar in Pythonfrom __future__ import divisionimport sysimport timeclass 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 = 300pbar = Progress(toolbar_width)pbar.start()for i in xrange(toolbar_width):    time.sleep(0.1) # do real work here    pbar.update(i)pbar.finish()
Progressbar in Python
python;optimization
As per my comments, I've not sure SE.CodeReview is the right place to get the help you are looking for.However, as I didn't read your question properly at first, I had a look at your code and changed a few things (please note that it's not exactly the same behavior as it used to be):extract the display logic in a method on its ownreuse update in start and finish (little changes here : this method now updates the object instead of just doing some display)removed self._seen because it didn't seem usefulHere the code :class Progress(object):    def __init__(self, maxval):        self._pct = 0        self.maxval = maxval    def update(self, value):        pct = int((value / self.maxval) * 100.0)        if self._pct != pct:            self._pct = pct            self.display()    def start(self):        self.update(0)    def finish(self):        self.update(self.maxval)    def display(self):        sys.stdout.write(|%-100s| %d%% % (u\u2588*self._pct, self._pct) + '\n')        sys.stdout.flush()