Last active
August 29, 2015 14:10
-
-
Save hirokazumiyaji/fe77b41416b7ed76c195 to your computer and use it in GitHub Desktop.
Progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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