Logging loop progress in Python like a pro with tqdm
Or the end of print(i)
inside a for
loop.
If you have ever wrote something like this:
for i in range(0,10000):
compute(i)
print(i)
to control the progress of your execution, this short article is for you 🙂.
All hail tqdm
tqdm, from the Arabic “taqadum” which means “progress” is one of the many Python libs that are as useful as they are easy to use. Install it the usual way with pip install tqdm
and then:
And you can even make it work with loops inside loops:
That’s it.
I hope this lib will help you and that you learn something today. The whole doc is available here.
tqdm comes with many options that can help you make the progress bar exactly as you want. tqdm also works very well in Jupyter notebook, just do from tqdm import tqdm_notebook
instead of from tqdm import tqdm
.
Thank you for reading:
If you like the article, the first tip is available here.
Don’t forget to subscribe if you want to receive my new posts directly into your inbox. I am soon starting something new and exciting 😎.
I write about tech in general and recently, more about how I built my new price competitor monitoring business.
See you next week for another Python tip 😃.