Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Last active August 29, 2015 14:10
Show Gist options
  • Save hirokazumiyaji/fe77b41416b7ed76c195 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/fe77b41416b7ed76c195 to your computer and use it in GitHub Desktop.
Progress
# coding: utf-8
from __future__ import absolute_import, unicode_literals, print_function
import sys
class Progress(object):
def __init__(self, max_count):
self._count = 0
self._max_count = max_count
def countup(self):
self._count += 1
def write(self):
if self._count > self._max_count:
return
percentage = int(self._count * 100 / self._max_count)
bar = '{}{}'.format('#' * percentage, ' ' * (100 - percentage))
sys.stdout.write('\r[{}] {}/{} {}%'.format(bar, self._count, self._max_count, percentage))
sys.stdout.flush()
if self._count == self._max_count:
sys.stdout.write('\n')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment