Display Progress Bar Using tqmd When Processing Python List – Python Tutorial

By | October 10, 2022

Whe often use python list to store many infomation to process. In this tutorial, we will introduce you how to display a progress bar when processing.

For example, if a list contains all lines in a file, we will process line by line, we can do as follows:

for line in all_lines:
    #process line

However, we can not see progress.

In order to see progess, we can use python tqmd library.

For example:

import tqdm
import time

x = range(10)

for i in tqdm.tqdm(x):
    print(i)
    time.sleep(1)

Run this code, we will see a progress in terminal.

Display Progress Bar Using tqmd When Processing Python List - Python Tutorial

Compare to code below:

for i in x:
    print(i)

We can find:

As to code for i in tqdm.tqdm(x), we also will get each element in x, which is same to for i in x.

Leave a Reply