Created
August 2, 2012 10:30
-
-
Save pranavraja/3236128 to your computer and use it in GitHub Desktop.
Python progress indicator
This file contains 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
import os, sys, time | |
def _term_width(): | |
return int(os.popen('stty size').read().split()[1]) | |
# `progress` is between 0 and 1 | |
def print_progress_update(progress, pipe=sys.stdout): | |
width = _term_width() - 3 | |
done = int(progress*width) | |
pipe.write('\r|%s>%s|' % (done*'=',' '*(width-done))) | |
if __name__ == '__main__': | |
for i in range(1,11): | |
print_progress_update(0.1*i) | |
sys.stdout.flush() | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment