summaryrefslogtreecommitdiff
path: root/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools.py')
-rw-r--r--tools.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools.py b/tools.py
index 1338526..d6b71b1 100644
--- a/tools.py
+++ b/tools.py
@@ -2,6 +2,24 @@ import numpy as np
import time
import datetime
import sys
+import math
+
+def ufloat_to_str(x):
+ msd = -int(math.floor(math.log10(x.std_dev())))
+ return '%.*f +/- %.*f' % (msd, x.nominal_value, msd, x.std_dev())
+
+def progress(seq):
+ "Print progress while iterating over `seq`."
+ n = len(seq)
+ print '[' + ' '*21 + ']\r[',
+ sys.stdout.flush()
+ for i, item in enumerate(seq):
+ if i % (n//10) == 0:
+ print '.',
+ sys.stdout.flush()
+ yield item
+ print ']'
+ sys.stdout.flush()
def debugger_hook(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():