#NEWLINE# def progress( iterator , enum = False , length = None ) : #NEWLINE# #INDENT# '\n    A helper utility to display a progress bar when iterating over a\n    collection of a fixed length or a generator (with a declared\n    length).\n\n    If enum=True, then equivalent to enumerate with a progress bar.\n    ' #NEWLINE# progress = ProgressBar ( ) #NEWLINE# length = ( len ( iterator ) if ( length is None ) else length ) #NEWLINE# gen = enumerate ( iterator ) #NEWLINE# while True : #NEWLINE# #INDENT# ( i , val ) = next ( gen ) #NEWLINE# progress ( ( ( ( i + 1.0 ) / length ) * 100 ) ) #NEWLINE# if enum : #NEWLINE# #INDENT# ( yield ( i , val ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( yield val )