utils.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. #def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'):
  3. def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'):
  4. """
  5. Call in a loop to create terminal progress bar
  6. @params:
  7. iteration - Required : current iteration (Int)
  8. total - Required : total iterations (Int)
  9. prefix - Optional : prefix string (Str)
  10. suffix - Optional : suffix string (Str)
  11. decimals - Optional : positive number of decimals in percent complete (Int)
  12. length - Optional : character length of bar (Int)
  13. fill - Optional : bar fill character (Str)
  14. """
  15. percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
  16. filledLength = int(length * iteration // total)
  17. bar = fill * filledLength + '-' * (length - filledLength)
  18. print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r')
  19. # Print New Line on Complete
  20. if iteration == total:
  21. print()
  22. def splitFileName(filename):
  23. path = None
  24. name = None
  25. ext = None
  26. (path, name) =os.path.split(filename)
  27. ext = name.split('.')[-1]
  28. name = name.split('.')[0]
  29. return (path,name, ext)