Ever wrote a super long loop and waited for the whole day for the loop to finish. And then you just found out there was a simple bug in your code for that reason your program stayed stuck at a certain place for a long amount of time? A progress bar can be a super simple way to find out on which state your loop is now and how long you have to wait for the loop to complete. This might also save you a huge amount of time. Perhaps you can get a cup of coffee meanwhile your loop completes. Anyway, without any further ado let's get looping. 😉
First, you need to install a PyPi package called
progress. If you already have pip installed then just type this command in terminal.
pip install progress
It won't take much time. When you are done just run this simple script and see your bar progressing.
from progress.bar import Bar bar = Bar('Processing', max=200000) for i in range(200000): # Do some work bar.next() bar.finish()
That' it! The program is pretty self-explanatory and simple. We are just running a loop and then showing the bar.
Lucky for you, this package has a total of 7 progress bars and 5 predefined spinners. If you don't like the style of the bars or the spinners you can also customize them as much as you wish. For example, you can change the fill, you can change the width, you can add a simple timer that will tell how much time has elapsed and how much time is left.
For all the detailed information, consider visiting this documentation.
Until next time, goodbye.
Claim your page on DEV before someone else does
Level up every day