Answer a question

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: 

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)
...
>>>
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐