progressbar progress bar abnormalities and correct use in python

conda installation package progressbar

conda install -c anaconda progressbar

progressbar import and application (unusual!)

import progressbar
total = 10000000
bar = progressbar.ProgressBar(maxval=total+1, widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
bar.start()

recs = {}
for i in range(total):
    recs[i] = i*i

bar.finish()

Run the above code and found progressbar has emerged, however! ! ! Progressbar did not play the desired effect! Found movable FIG follows:

Directly from 0% to 100%

I waited four seconds, progress directly from 0% to 100%! Fortunately, four seconds, if the 40 minutes it? I believe small party partner will like me, waited five minutes or 0%, they think the card system is dead!

How to break? How to break?

progressbar import and application (achieve the desired effect!)

After I try to join a counter counter, everything to be perfect, directly on the code:

import progressbar
total = 10000000
counter = 0 #新增加
bar = progressbar.ProgressBar(maxval=total+1, widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
bar.start()

recs = {}
for i in range(total):

    counter+=1 #新增加
    bar.update(counter) # #新增加,用于Update the progressbar

    recs[i] = i*i

bar.finish()

Run the code again, progressbar effect has been found! ! ! Found movable FIG follows:

perfect!

The perfect solution! Never worry about not see the progress of the run it!

If you learn, welcome attention + + collection points like oh ~ ~

Published 11 original articles · won praise 3 · Views 1148

Guess you like

Origin blog.csdn.net/weixin_45281949/article/details/104056429