简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM