Created
July 25, 2013 06:25
-
-
Save kavinyao/6077326 to your computer and use it in GitHub Desktop.
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 sys | |
import math | |
import time | |
def progress_bar(progress, col_width=80): | |
""" | |
Text progress bar in command line. | |
Pre-condition: the cursor is at a new line. | |
Post-condition: the cursor is at the end of the same line. | |
""" | |
progress_width = col_width - 10 | |
finished = int(progress * progress_width) | |
progress_str = '#'*finished + '-'*(progress_width-finished) | |
sys.stdout.write('\r[%s](%.1f%%)' % (progress_str, 100*progress)) | |
sys.stdout.flush() | |
limit = 42 | |
for i in range(limit): | |
progress = 1.0*(i+1)/limit | |
progress_bar(progress) | |
time.sleep(0.1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment