diff options
Diffstat (limited to 'tools.py')
-rw-r--r-- | tools.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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(): |