Advertisement
vidzor

progressBar

Sep 7th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. def printProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='='):
  2.     """
  3.     Call in a loop to create terminal progress bar
  4.     @params:
  5.         iteration   - Required  : current iteration (Int)
  6.         total       - Required  : total iterations (Int)
  7.         prefix      - Optional  : prefix string (Str)
  8.         suffix      - Optional  : suffix string (Str)
  9.         decimals    - Optional  : positive number of decimals in percent complete (Int)
  10.         length      - Optional  : character length of bar (Int)
  11.         fill        - Optional  : bar fill character (Str)
  12.     Example usage:
  13.         for i, img in enumerate(img_files):
  14.             printProgressBar(
  15.                 i+1, len(img_files), prefix = f'Loading Data: {i+1}/{len(img_files)}', length = 50
  16.             )
  17.     """
  18.     percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
  19.     filledLength = int(length * iteration // total)
  20.     bar = fill * filledLength + '.' * (length - filledLength)
  21.     os.sys.stdout.write('\r %s |%s| %s%% %s' % (prefix, bar, percent, suffix))
  22.     os.sys.stdout.flush()
  23.     # Print New Line on Complete
  24.     if iteration == total:
  25.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement