Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import sys
  2.  
  3.  
  4. # Print iterations progress
  5. def print_progress(iteration, total,
  6. prefix='', suffix='', decimals=1, bar_length=100):
  7. """
  8. Call in a loop to create terminal progress bar
  9.  
  10. @params:
  11. iteration - Required: current iteration (Int)
  12. total - Required: total iterations (Int)
  13. prefix - Optional: prefix string (Str)
  14. suffix - Optional: suffix string (Str)
  15. decimals - Optional: >0 number of decimals in percent complete (Int)
  16. bar_length - Optional: character length of bar (Int)
  17. """
  18.  
  19. percents = f'{100 * (iteration / float(total)):.2f}'
  20.  
  21. filled_length = int(round(bar_length * iteration / float(total)))
  22. bar = f'{"█" * filled_length}{"-" * (bar_length - filled_length)}'
  23.  
  24. sys.stdout.write(f'\r{prefix} |{bar}| {percents}% {suffix}'),
  25.  
  26. if iteration == total:
  27. sys.stdout.write('\n')
  28. sys.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement