Commits

James Taylor committed 0e24f15 Merge

Comments (0)

Files changed (1)

lib/bx/cookbook/progress_bar.py

 import sys
 
 class ProgressBar:
-    def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
+    def __init__(self, minValue = 0, maxValue = 10, totalWidth=72):
         self.progBar = "[]"   # This holds the progress bar string
         self.min = minValue
         self.max = maxValue
     def __str__(self):
         return str(self.progBar)
 
+def iterprogress( sized_iterable ):
+    """
+    Iterate something printing progress bar to stdout
+    """
+    pb = ProgressBar( 0, len( sized_iterable ) )
+    for i, value in enumerate( sized_iterable ):
+        yield value
+        pb.update_and_print( i, sys.stderr )
+
 if __name__ == "__main__":
     import time
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.