Progress bars and log output in Jupyter notebooks
I wanted to have just one updatable 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.
1import time 2import random 3from tqdm.auto import tqdm 4from IPython.display import display, Markdown 5 6info_line = display(Markdown(''), display_id=True) 7 8for x in tqdm(range(0,5), position = 0): 9 for y in tqdm(range(0,5), position = 1, leave=False): 10 x = random.randint(1, 10) 11 b = "Loading" + "." * x 12 info_line.update(Markdown(b)) 13 time.sleep(0.5)