Created
January 30, 2017 10:40
-
-
Save Jerakin/3b7c24f9324d00eac03c1464a1191540 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
# Implementation of Brian Khuu's progress bar from http://stackoverflow.com/questions/3160699/python-progress-bar | |
# with some small tweaks to formatting | |
# | |
# Accepts a float between 0 and 1. Any int will be converted to a float. | |
# A value under 0 represents a 'halt'. | |
# A value at 1 or bigger represents 100% | |
# | |
# Usage | |
#for i in len(10): | |
# progressbar.update_progress((i+1)/len(10)) | |
# | |
import sys | |
def update_progress(progress): | |
bar_length = 50 # Modify this to change the length of the progress bar | |
status = "" | |
if isinstance(progress, int): | |
progress = float(progress) | |
if not isinstance(progress, float): | |
progress = 0 | |
status = "error: progress var must be float\r\n" | |
if progress < 0: | |
progress = 0 | |
status = "Halt...\r\n" | |
if progress >= 1: | |
progress = 1 | |
status = "Done...\r\n" | |
block = int(round(bar_length*progress)) | |
text = "\rPercent: [{}] {:.1f}% {}".format("#"*block + "-"*(bar_length-block), progress*100, status) | |
sys.stdout.write(text) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment