Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active March 14, 2024 09:51
Show Gist options
  • Save izikeros/d05e2f98ac14ecf97c65eb34a6cb7065 to your computer and use it in GitHub Desktop.
Save izikeros/d05e2f98ac14ecf97c65eb34a6cb7065 to your computer and use it in GitHub Desktop.
[simple progress bar] Simple, text-based progress bar #python
# Print iterations progress
# from: https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
def print_progress(iteration, total, prefix="", suffix="", decimals=1, bar_length=100):
"""Call in a loop to create terminal progress bar.
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent
complete (Int)
bar_length - Optional : character length of bar (Int)
"""
if total > 0:
str_format = "{0:." + str(decimals) + "f}"
percents = str_format.format(100 * (iteration / float(total)))
filled_length = int(round(bar_length * iteration / float(total)))
bar = "█" * filled_length + "-" * (bar_length - filled_length)
(sys.stdout.write(f"\r{prefix} |{bar}| {percents}% {suffix}"), )
if iteration == total:
sys.stdout.write("\n")
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment