0

I've got this function that takes some time to complete and I'd like to display the current progress per element in the list.

This is how it's coded:

import progressbar

def func(self):
    bar = progressbar.ProgressBar(
        maxval=len(some_list),
        widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()]
    )
    progress = 0
    bar.start()
    for r in some_list:
        #heavy calculation
        progress += 1
        bar.update(progress)
    bar.finish()

Yet when I run, the progressbar isn't displayed (nothing in fact is), the function just does its thing and when the function ends 20 seconds later I suddenly get the full bar in the console

What am I doing wrong?

I'm using Kubuntu latest version with python 3.7.4 and PyCharm.

accdias
  • 4,552
  • 3
  • 18
  • 30
Wouter Vandenputte
  • 1,728
  • 4
  • 21
  • 39

1 Answers1

3

Consider running it not from an IDE, sometimes they get a messy std output. Just run it with plain python like this:

python3 your_script.py
marcos
  • 4,253
  • 1
  • 9
  • 20