When using the tqdm progress bar: can I add a message to the same line as the progress bar in a loop?
I tried using the "tqdm.write" option, but it adds a new line on every write. I would like each iteration to show a short message next to the bar, that will disappear in the next iteration. Is this possible?
You can change the description to show a small message before the progress bar, like this:
from tqdm import trange
from time import sleep
t = trange(100, desc='Bar desc', leave=True)
for i in t:
t.set_description("Bar desc (file %i)" % i)
t.refresh() # to show immediately the update
sleep(0.01)
/EDIT: in the latest releases of tqdm
, you can use t.set_description("text", refresh=True)
(which is the default) and remove t.refresh()
(thanks to Daniel for the tip).