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.
Top comments (6)
This is wrong. By default, Debian does not have python or pip which are different packages in the
apt
environment.Oops, fixing right now. And thanks for correcting. 😊
You should have added this gif to the post.
It's wonderful. Well done!
I wanted to add some. But don't know how to. How did you do that?
Look up the section for images here. = dev.to/p/editor_guide
Some comments may only be visible to logged-in visitors. Sign in to view all comments.