NiltonVolpato / python-progressbar

Text progress bar library for Python
Other
412 stars 105 forks source link

Division by zero in `ProgressBar.percentage` #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It would be nice if this division by zero was avoided:

diff --git a/progressbar/progressbar.py b/progressbar/progressbar.py
--- a/progressbar/progressbar.py
+++ b/progressbar/progressbar.py
@@ -184,7 +184,7 @@

     def percentage(self):
         """Returns the progress as a percentage."""
-        if self.currval >= self.maxval:
+        if self.currval >= self.maxval or self.maxval == 0:
             return 100.0
         return self.currval * 100.0 / self.maxval

Original issue reported on code.google.com by wole...@gmail.com on 8 Aug 2014 at 6:57

frost-nzcr4 commented 8 years ago

Same problem, to avoid one can use a workaround:

progress = ProgressBar(maxval=my.objects.count() or None).start()
yarikoptic commented 8 years ago

I believe it was fixed in #50