-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
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
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. |