I would like to display text in a ring-like buffer below a tqdm progress bar. This text would not necessarily be updated with every update of the bar. When using the .write() function of tqdm, text is only printed to the right of the bar, which is not desired. I'm not sure if this is possible with tqdm or not.
I would like it to look like this:
70%|███████ | 7/10 [00:00<00:00, 9.65it/s]
Message 2 ....
Message 3 ....
Message 4 ....
Message 5 ....
When a new Message is printed, Message 2 is deleted and the messages move up in the stack. I'm not tied to tqdm but I have been using it so far.
You could use a second progress bar, where you only use the description.
import random
import time
from tqdm import tqdm
n_iter = 1000
with tqdm(total=n_iter, position=1, bar_format='{desc}', desc='No high number so far.') as desc:
for i in tqdm(range(n_iter), total=n_iter, position=0):
x = random.random()
if x > 0.95:
desc.set_description('High random number: %f' % x)
time.sleep(0.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With