mirror of
https://github.com/TomHodson/tomhodson.github.com.git
synced 2025-06-26 10:01:18 +02:00
add progress bar post
This commit is contained in:
parent
838e00ed59
commit
a239690854
30
_posts/2023-06-22-tqdm_and_printing_in_notebooks.md
Normal file
30
_posts/2023-06-22-tqdm_and_printing_in_notebooks.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
title: Progress bars and log output in Jupyter notebooks
|
||||||
|
excerpt:
|
||||||
|
layout: post
|
||||||
|
image: /assets/blog/progress_bars/bar.png
|
||||||
|
alt: An image of a nice animated progress bar in a jupyter notebook output cell.
|
||||||
|
---
|
||||||
|
I wanted to have just one updateable line of output that would play nicely with a tqdm progress bar. After playing around with `print(s, end="\r")` I settled on using `Ipython.display` with a handle. The problem with the print approach is that it doesn't work when the output is shorter than the previous line.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
from tqdm.auto import tqdm
|
||||||
|
from IPython.display import display, Markdown
|
||||||
|
|
||||||
|
info_line = display(Markdown(''), display_id=True)
|
||||||
|
|
||||||
|
for x in tqdm(range(0,5), position = 0):
|
||||||
|
for y in tqdm(range(0,5), position = 1, leave=False):
|
||||||
|
x = random.randint(1, 10)
|
||||||
|
b = "Loading" + "." * x
|
||||||
|
info_line.update(Markdown(b))
|
||||||
|
time.sleep(0.5)
|
||||||
|
```
|
||||||
|
<figure>
|
||||||
|
<img src="/assets/blog/progress_bars/bar.png"/>
|
||||||
|
<figcaption>
|
||||||
|
What it looks like in the end.
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
BIN
assets/blog/progress_bars/bar.png
Normal file
BIN
assets/blog/progress_bars/bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Loading…
x
Reference in New Issue
Block a user