How do I use a progress bar when my script is doing some task that is likely to take time?
For example, a function which takes some time to complete and returns
a little more generic answer of jelde015 (credit to him of course)
for updating the loading bar manually will be:
import sys
from math import *
def loadingBar(i, N, size):
percent = float(i) / float(N)
sys.stdout.write("\r"
+ str(int(i)).rjust(3, '0')
+"/"
+str(int(N)).rjust(3, '0')
+ ' ['
+ '='*ceil(percent*size)
+ ' '*floor((1-percent)*size)
+ ']')
and calling it by:
loadingBar(7, 220, 40)
will result:
007/220 [= ]
just call it whenever you want with the current i
value.
set the size
as the number of chars the bar should be