🐍 Python tips 2: logging loop progress like a pro · daolf

🐍 Python tips 2: logging loop progress like a pro

Or the end of print(i) inside a for loop.

If you have ever wrote something like this:

    for i in range(0,10000):

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.

If you liked this post, do not forget to subscribe to my newsletter and see you soon for another Python tips.

You can read the first one here

If you liked this article, you can follow me on Twitter, I tweet about bootstrapping, indie-hacking, startups and code 😊
comments powered by Disqus