Last active
February 7, 2025 15:47
-
-
Save azlux/7b8f449ac7fa308d45232c3a281be7bb to your computer and use it in GitHub Desktop.
Progress bar into the terminal in python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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