-
-
Save splch/b9ca7f11b945863890a9d0e716e085f5 to your computer and use it in GitHub Desktop.
a simple and useful progress bar in python
This file contains 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
import time, sys | |
def progress(iterable, length=33): | |
total, start = len(iterable), time.monotonic() | |
for count, it in enumerate(iterable, 1): | |
yield it | |
if count % max(1, total // 10000) == 0 or count == total: | |
percent = count / total | |
sys.stdout.write( | |
f'\r▕{"█" * int(length * percent) + " " * (length - int(length * percent))}▏ ' | |
f'{percent * 100:.2f}% ' | |
f'{(time.monotonic() - start) / count * (total - count):.2f}s' | |
), sys.stdout.flush() | |
sys.stdout.write(f'\r▕{"█" * length}▏ 100.00% {time.monotonic() - start:.2f}s\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Import the
progress
functionTest the function