Progress bars in Python!!!!
Muhimen

Muhimen @muhimen123

About: Nothing more than a programmer nothing less than a programmer. Loves to solve Rubik's cubes in spare time.

Location:
Bangladesh
Joined:
Nov 21, 2019

Progress bars in Python!!!!

Publish Date: Apr 8 '20
28 6

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

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

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.

Comments 6 total

  • Maximilian Burszley
    Maximilian BurszleyApr 8, 2020

    If you already have pip installed(by default it is installed in Mac and Linux)

    This is wrong. By default, Debian does not have python or pip which are different packages in the apt environment.

    • Muhimen
      MuhimenApr 8, 2020

      Oops, fixing right now. And thanks for correcting. 😊

  • Srikanth
    SrikanthApr 8, 2020

    progress

    You should have added this gif to the post.
    It's wonderful. Well done!

  • Nill Webdev
    Nill WebdevMar 29, 2021

    Progress bars are excellent gamification examples. They aim to encourage a special kind of thinking. Progress bars are the interactive trackers showing information that learners need the most:
    *milestones (what’s already achieved);
    *future targets;
    *possible badges to earn;
    *different learning paths to choose;
    *option to revisit previous levels.
    Progress bars are crucial for building learners’ engagement and motivation. People will love your education app if it makes them feel the purpose of what they’ve already done and the appeal of future achievements.

Add comment