summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-09-08 11:32:56 -0400
committerStan Seibert <stan@mtrr.org>2011-09-08 11:32:56 -0400
commitaeb16cf530767cd16c23c258802325b726e577d7 (patch)
tree17c5d62db8edeb47bb11dfdb3dc0e15421b80dd6
parentbec629d6cb050164dc3b96c832a5e25f6840f754 (diff)
downloadchroma-aeb16cf530767cd16c23c258802325b726e577d7.tar.gz
chroma-aeb16cf530767cd16c23c258802325b726e577d7.tar.bz2
chroma-aeb16cf530767cd16c23c258802325b726e577d7.zip
Prevent progress() from raising an exception if you pass in a sequence with less than 10 elements
-rw-r--r--tools.py3
1 files changed, 2 insertions, 1 deletions
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