🐍 Logging loop progress like a pro in Python

Pierre - Mar 18 '19 - - Dev Community

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)
Enter fullscreen mode Exit fullscreen mode

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:

VoilĂ  !VoilĂ  !

And you can even make it work with loops inside loops:

VoilĂ ! VoilĂ !VoilĂ ! VoilĂ !

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

I hope this short post will help you log loops better and impress your colleagues.

Please tell me in the comments if you liked the post and don't forget to subscribe to my newsletter, there is more to come (And you'll also get the first chapters of my next ebook for free 😎).

If you like JS, I've just published something you might like.

And if you prefer git, I got you covered.

. . . . . . . . . . . . . . . . . . . . . . . . . . .