Skip to content

Instantly share code, notes, and snippets.

@eltrujo
Last active March 22, 2022 22:48
Show Gist options
  • Save eltrujo/d02cbfd857d6497227fec5e2b381fcd7 to your computer and use it in GitHub Desktop.
Save eltrujo/d02cbfd857d6497227fec5e2b381fcd7 to your computer and use it in GitHub Desktop.
Python Progress Bar on Command Window
import sys
def update_progress(progress, prefix='Progress', suffix=''):
bar_len = 60
filled_len = int(round(bar_len * progress))
perc = round(100.0 * progress, 1)
bar = '█' * filled_len + '-' * (bar_len - filled_len)
ending_char = '\r' if progress != 1 else '\n'
sys.stdout.write(f' {prefix} [{bar}] {perc}% {suffix}{ending_char}')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment