Skip to content

Instantly share code, notes, and snippets.

@azlux
Last active February 7, 2025 15:47
Show Gist options
  • Save azlux/7b8f449ac7fa308d45232c3a281be7bb to your computer and use it in GitHub Desktop.
Save azlux/7b8f449ac7fa308d45232c3a281be7bb to your computer and use it in GitHub Desktop.
Progress bar into the terminal in python3
def progress_bar(current, total, bar_length=50):
percent = int(round((current / total) * 100))
nb_bar_fill = int(round((bar_length * percent) / 100))
bar_fill = '#' * nb_bar_fill
bar_empty = ' ' * (bar_length - nb_bar_fill)
sys.stdout.write(f"\r [{str(bar_fill + bar_empty)}] {percent}% ({current}/{total}) ")
sys.stdout.flush()
def bar_example():
for i in range(20):
time.sleep(0.5)
progress_bar(i, 99, 200)
if __name__ == '__main__':
bar_example()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment