Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, tqdm: is there a way to print something between a progress bar and what is printed using tqdm.write?

I have a group of progress bars and I use tqdm.write to print log messages above them while they are running. For aesthetic reasons, I'd like to visually separate the log messages from the progress bars with an empty line or something like a repeated "=", like:

Log message 1                                                                                  
Log message 2                                                                              
Log message 3 
==================================================                                                                                                
Progress 1: 50%|█████████████████              |
Progress 2: 50%|█████████████████              |

Is there any way to achieve that?

like image 682
janluke Avatar asked Oct 18 '25 15:10

janluke


1 Answers

It's a bit of a hack, but the following might be a start for you:

from tqdm import tqdm
from tqdm._utils import _term_move_up
import time

pbar = tqdm(range(5))
border = "="*50
clear_border = _term_move_up() + "\r" + " "*len(border) + "\r"
for i in pbar:
    pbar.write(clear_border + "Message %d" % i)
    pbar.write(border)
    pbar.update()
    time.sleep(0.1)
like image 200
Joe Halliwell Avatar answered Oct 21 '25 05:10

Joe Halliwell