How To Add A Progress Bar In Python With Just One Line
In this Python Tutorial I show you how you can add a Progress Bar to your Python code in just one line of code! We use the great
tqdm module for this that can simply be installed with
pip install tqdm. I show you the iterable based and the manually controlled approach.
pip install tqdm
Iterable based approach
from tqdm import tqdm, trange import time for i in tqdm([1, 2, 3, 4, 5]): time.sleep(0.2) print('done')
Special optimised instance of tqdm(range(i))
for i in trange(10): time.sleep(0.1) print('done')
Manual approach 1: Use a with statement
# we can provide the optional 'total' parameter with tqdm(total=100) as pbar: for i in range(10): time.sleep(0.1) pbar.update(10) print('done')
Manual approach 2: Assign to a variable
Dont forget to call
close() at the end!!!
pbar = tqdm(total=100) for i in range(10): time.sleep(0.1) pbar.update(10) pbar.close() print('done')
Join My Newsletter! Get Python and ML tips emailed directly to your inbox. Each month you’ll get a summary of all the content I created, including the newest videos, articles, promotions, tips, and more.
Implement popular Machine Learning algorithms from scratch using only built-in Python modules and numpy.
Advanced Python Tutorials. It covers topics like collections, decorators, generators, multithreading, logging, and much more.
Learn all the necessary basics to get started with this deep learning framework.