Skip to content

Instantly share code, notes, and snippets.

@fmayer
Last active December 19, 2015 12:39
Show Gist options
  • Save fmayer/5956708 to your computer and use it in GitHub Desktop.
Save fmayer/5956708 to your computer and use it in GitHub Desktop.
class ProgressBar(object):
def __init__(self, n, current=0, width=40, output=sys.stdout):
self.n = n
self.current = current
self.width = width
self.step = self.n / self.width
self.output = output
def draw_one(self):
self.output.write("-")
def draw(self):
for _ in xrange(self.current):
self.poke()
def poke(self, n=1):
if self.current > self.n:
raise ValueError("ProgressBar overflowed.")
diff = int((self.current + n) / self.step) - int(self.current / self.step)
for _ in xrange(diff):
self.draw_one()
self.current += n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment