Progress bar….

I got tired of waiting for code to finish and having no idea how far along it was.  Stack exchange provided an elegant solution of which I modified:

 import time,sys

def update_progress(step,datalen):
 progress = float(step)/float(datalen)
 barLength = 10 # Modify this to change the length of the progress bar
 status = ""
 if progress < 0:
 progress = 0
 status = "Halt...rn"
 if step >= datalen-1:
 progress = 1
 status = "Done...rn"

block = int(round(barLength*progress))
 text = "rPercent: [%s] %2.2f%% %s" % ("#"*block +
"-"*(barLength-block),
 progress*100, status)
 sys.stdout.write(text)
 sys.stdout.flush()

datalen=150
 for i in range(datalen):
 time.sleep(0.1) #just to slow it down!
 update_progress(i,datalen)

UPDATE (10/31/13)

here’s a cython version:
 cdef void update_progress(int step, int datalen):
 cdef float progress = float(step)/float(datalen)
 cdef int barLength = 10 # Modify this to change the length of the
 progress bar
 status = ""
 if progress < 0:
 progress = 0
 status = "Halt...rn"
 if step >= datalen-1:
 progress = 1
 status = "Done...rn"

cdef int block = int(np.round(barLength*progress))
 text = "rPercent: [%s] %2.2f%% %s" % ("#"*block +
"-"*(barLength-block),
 progress*100, status)
 sys.stdout.write(text)
 sys.stdout.flush()