Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove progressbar in tqdm once the iteration is complete

How can I archive this?

from tqdm import tqdm    
for link in tqdm(links):
        try:
            #Do Some Stff
        except:
            pass  
print("Done:")  

Result:

100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 111.50it/s]
Done:   

100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 111.50it/s]
Done:  

Expected Result (Showing the status bar but don't print it after into the console)

Done:  
Done: 
like image 243
request Avatar asked Sep 01 '25 10:09

request


1 Answers

tqdm actually takes several arguments, one of them is leave, which according to the docs:

If [default: True], keeps all traces of the progressbar upon termination of iteration. If None, will leave only if position is 0

So:

>>> for _ in tqdm(range(2)):
...     time.sleep(1)
...
100%|██████████████████████████████████████████████████████| 2/2 [00:02<00:00,  1.01s/it]

Whereas setting leave=False yields:

>>> for _ in tqdm(range(2), leave=False):
...     time.sleep(1)
...
>>>
like image 191
yatu Avatar answered Sep 02 '25 23:09

yatu