Skip to content

Commit

Permalink
Create progress-bars.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jatonline authored Aug 19, 2024
1 parent b7adb67 commit 40ebcc4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Python/progress-bars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Progress bars for long-running loops or tasks

If you have a loop that has a number of iterations or takes a long time to run, you can get an easy progress bar (with an estimated time to completion) using tools like [tqdm](https://tqdm.github.io/) or [Rich](https://rich.readthedocs.io/en/latest/progress.html). They also work in Jupyter notebooks.

## tqdm

Change your loop from:

```python
for i in range(10000):
...
```

to:

```python
from tqdm import tqdm
for i in tqdm(range(10000)):
...
```

And get this for free:

```
76%|████████████████████████████ | 7568/10000 [00:33<00:10, 229.00it/s]
```

You can also manually update the progress bar in your code using [`tqdm.update()`](https://tqdm.github.io/docs/tqdm/#update).

## Rich

Rich works in a similar way, and also provides [rich console output](rich-console-output.md) more generally.

0 comments on commit 40ebcc4

Please sign in to comment.