From aeb16cf530767cd16c23c258802325b726e577d7 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Thu, 8 Sep 2011 11:32:56 -0400 Subject: Prevent progress() from raising an exception if you pass in a sequence with less than 10 elements --- tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools.py b/tools.py index d6b71b1..a884db3 100644 --- a/tools.py +++ b/tools.py @@ -13,8 +13,9 @@ def progress(seq): n = len(seq) print '[' + ' '*21 + ']\r[', sys.stdout.flush() + update_interval = max(n // 10, 1) for i, item in enumerate(seq): - if i % (n//10) == 0: + if i % update_interval == 0: print '.', sys.stdout.flush() yield item -- cgit