Barra de progresso para ipython e notebook ipython

import sys, time
try:
from IPython.core.display import clear_output
have_ipython
= True
except ImportError:
have_ipython
= False

class ProgressBar:
def __init__(self, iterations):
self.iterations = iterations
self.prog_bar = '[]'
self.fill_char = '*'
self.width = 40
self.__update_amount(0)
if have_ipython:
self.animate = self.animate_ipython
else:
self.animate = self.animate_noipython

def animate_ipython(self, iter):
try:
clear_output
()
except Exception:
# terminal IPython has no clear_output
pass
print 'r', self,
sys
.stdout.flush()
self.update_iteration(iter + 1)

Uso:

p = Progressbar(120)

for i in range(1, 120+1):
p
.animate(i)