tqdm is a must need python package for all data scientists and artificial intelligence researchers/developers. Sometimes, we need to visualize what is going on in the background. Some programs may require hours to several days to finish. In that case, a progress bar is required. Here, we will learn how to use tqdm package in the Python programming language.

Installing tqdm using pip

tqdm installation is similar to other pip installations. Just follow the same structure-

pip install tqdm

Installing tqdm in an anaconda environment

Similar to pip, follow the similar structure for an anaconda-

conda install tqdm

Simplest code for tqdm example

from tqdm import tqdm
import time

for i in tqdm(range(100)):
    print("shahinnur.com")
    time.sleep(1)

This code block will make a progress bar up to the 100 range. To use tqdm, we have to define the range, how long it will go.

Line number 1 and 4 is the main code for tqdm. Associated code is for additional use.

Update tqdm progressbar

The above code updates the progress bar for every iteration. However, a manual update is possible. In that case, we must use the “with” keyword outside the loop. The example is shown below-

from tqdm import tqdm
import time

with tqdm(total=1000) as progressBar:
    for i in range(50):
        time.sleep(1)
        print("shahinnur.com")
        progressBar.update(20)

In this code, the progress bar will update every 20 iterations.

progress bar using tgdm and python

For more information please follow the official tqdm documentation.

Thank you very much.

0 0 votes
Article Rating
0
Would love your thoughts, please comment.x
()
x