How do I use a progress bar when my script is doing some task that is likely to take time?
For example, a function which takes some time to complete and returns
A very simple approach:
def progbar(count: int) -> None: for i in range(count): print(f"[{i*'#'}{(count-1-i)*' '}] - {i+1}/{count}", end="\r") yield i print('\n')
And the usage:
from time import sleep for i in progbar(10): sleep(0.2) #whatever task you need to do