Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, sys
- # update_progress() : Displays or updates a console progress bar
- ## 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%
- def update_progress(progress):
- barLength = 30 # 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(barLength*progress))
- progress = int(progress * 100)
- text = "\rProgress: [{0}] {1}% {2}".format( "■"*block + "."*(barLength-block), progress, status)
- sys.stdout.write(text)
- sys.stdout.flush()
- # print("progress : 0->1")
- # for i in range(101):
- # time.sleep(0.1)
- # update_progress(float(i/100.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement