Index: sansutil/calcthread.py
===================================================================
--- sansutil/calcthread.py	(revision 402501942f1285a702e0d42b78fbaa03aae64c6d)
+++ sansutil/calcthread.py	(revision 4a96b8b36a60c2288a9134e28bbfda8a28fdca3c)
@@ -5,18 +5,21 @@
 #
 
-import thread, traceback
-
+import thread
+import traceback
 import sys
 
-if sys.platform.count("darwin")>0:
+if sys.platform.count("darwin") > 0:
     import time
     stime = time.time()
+    
     def clock():
-        return time.time()-stime
+        return time.time() - stime
+    
     def sleep(t):
-        return time.sleep(t)    
+        return time.sleep(t)
 else:
     from time import clock
     from time import sleep
+
 
 class CalcThread:
@@ -113,10 +116,6 @@
     """
 
-    def __init__(self,
-                 completefn = None,
-                 updatefn   = None,
-                 yieldtime  = 0.01,
-                 worktime   = 0.01
-                 ):
+    def __init__(self, completefn=None, updatefn=None,
+                 yieldtime=0.01, worktime=0.01):
         """Prepare the calculator"""
         self.yieldtime     = yieldtime
@@ -134,12 +133,12 @@
         method for details of the arguments to the work unit."""
         self._lock.acquire()
-        self._queue.append((args,kwargs))
+        self._queue.append((args, kwargs))
         # Cannot do start_new_thread call within the lock
         self._lock.release()
         if not self._running:
-            self._time_for_update = clock()+1e6
-            thread.start_new_thread(self._run,())
-
-    def requeue(self,*args,**kwargs):
+            self._time_for_update = clock() + 1e6
+            thread.start_new_thread(self._run, ())
+
+    def requeue(self, *args, **kwargs):
         """Replace the work unit on the end of the queue.  See the compute()
         method for details of the arguments to the work unit."""
@@ -147,11 +146,11 @@
         self._queue = self._queue[:-1]
         self._lock.release()
-        self.queue(*args,**kwargs)
-
-    def reset(self,*args,**kwargs):
+        self.queue(*args, **kwargs)
+
+    def reset(self, *args, **kwargs):
         """Clear the queue and start a new work unit.  See the compute()
         method for details of the arguments to the work unit."""
         self.stop()
-        self.queue(*args,**kwargs)
+        self.queue(*args, **kwargs)
 
     def stop(self):
@@ -171,5 +170,6 @@
         self._lock.release()
 
-    def isrunning(self): return self._running
+    def isrunning(self):
+        return self._running
 
     def ready(self, delay=0.):
@@ -189,11 +189,12 @@
 
         # Only called from within the running thread so no need to lock
-        if self._running and self.yieldtime>0 and clock()>self._time_for_nap:
-            # print "sharing"
+        if self._running and self.yieldtime > 0 \
+            and clock() > self._time_for_nap:
             sleep(self.yieldtime)
             self._time_for_nap = clock() + self.worktime
-        if self._interrupting: raise KeyboardInterrupt
-
-    def update(self,**kwargs):
+        if self._interrupting:
+            raise KeyboardInterrupt
+
+    def update(self, **kwargs):
 
         """Update GUI with the lastest results from the current work unit."""
@@ -206,10 +207,11 @@
             self.updatefn(**kwargs)
             sleep(self.yieldtime)
-            if self._interrupting: raise KeyboardInterrupt
+            if self._interrupting:
+                raise KeyboardInterrupt
         else:
             self.isquit()
         return
 
-    def complete(self,**kwargs):
+    def complete(self, **kwargs):
         """Update the GUI with the completed results from a work unit."""
         if self.completefn != None:
@@ -218,5 +220,5 @@
         return
 
-    def compute(self,*args,**kwargs):
+    def compute(self, *args, **kwargs):
         """Perform a work unit.  The subclass will provide details of
         the arguments."""
@@ -233,15 +235,14 @@
         while 1:
             self._lock.acquire()
-            # print "lock aquired"
-            self._time_for_nap = clock()+self.worktime
+            self._time_for_nap = clock() + self.worktime
             self._running = True
-            if self._queue == []: break
+            if self._queue == []:
+                break
             self._interrupting = False
-            args,kwargs = self._queue[0]
+            args, kwargs = self._queue[0]
             self._queue = self._queue[1:]
             self._lock.release()
-            # print "lock released"
             try:
-                self.compute(*args,**kwargs)
+                self.compute(*args, **kwargs)
             except KeyboardInterrupt:
                 pass
@@ -251,9 +252,10 @@
         self._running = False
 
+
 # ======================================================================
 # Demonstration of calcthread in action
 class CalcDemo(CalcThread):
     """Example of a calculation thread."""
-    def compute(self,n):
+    def compute(self, n):
         total = 0.
         for i in range(n):
@@ -264,5 +266,9 @@
         self.complete(total=total)
 
+
 class CalcCommandline:
+    """
+        Test method
+    """
     def __init__(self, n=20000):
         print thread.get_ident()
@@ -283,19 +289,15 @@
         while not self.done:
             sleep(1)
-            print "Main thread %d at %.2f"%(thread.get_ident(),clock()-self.starttime)
-
-    def update(self,i=0):
-        print "Update i=%d from thread %d at %.2f"%(i,thread.get_ident(),clock()-self.starttime)
+            print "Main thread %d at %.2f" % (thread.get_ident(),
+                                              clock() - self.starttime)
+
+    def update(self, i=0):
+        print "Update i=%d from thread %d at %.2f" % (i, thread.get_ident(),
+                                                      clock() - self.starttime)
         self.work.ready(2.5)
 
-    def complete(self,total=0.0):
-        print "Complete total=%g from thread %d at %.2f"%(total,thread.get_ident(),clock()-self.starttime)
+    def complete(self, total=0.0):
+        print "Complete total=%g from thread %d at %.2f" % (total,
+                                                    thread.get_ident(),
+                                                    clock() - self.starttime)
         self.done = True
-
-if __name__ == "__main__":
-    CalcCommandline()
-
-# version
-__id__ = "$Id: calcthread.py 249 2007-06-15 17:03:01Z ziwen $"
-
-# End of file
Index: sansutil/err1d.py
===================================================================
--- sansutil/err1d.py	(revision 402501942f1285a702e0d42b78fbaa03aae64c6d)
+++ sansutil/err1d.py	(revision 4a96b8b36a60c2288a9134e28bbfda8a28fdca3c)
@@ -1,4 +1,3 @@
 # This program is public domain
-
 """
 Error propogation algorithms for simple arithmetic
@@ -8,10 +7,9 @@
 integers, so be sure to create them with floating point inputs.
 """
-
-
 from __future__ import division  # Get true division
 import numpy
 
-def div(X,varX, Y,varY):
+
+def div(X, varX, Y, varY):
     """Division with error propagation"""
     # Direct algorithm:
@@ -28,5 +26,6 @@
     return Z, varZ
 
-def mul(X,varX, Y,varY):
+
+def mul(X, varX, Y, varY):
     """Multiplication with error propagation"""
     # Direct algorithm:
@@ -43,5 +42,6 @@
     return Z, varZ
 
-def sub(X,varX, Y, varY):
+
+def sub(X, varX, Y, varY):
     """Subtraction with error propagation"""
     Z = X - Y
@@ -49,5 +49,6 @@
     return Z, varZ
 
-def add(X,varX, Y,varY):
+
+def add(X, varX, Y, varY):
     """Addition with error propagation"""
     Z = X + Y
@@ -55,15 +56,17 @@
     return Z, varZ
 
-def exp(X,varX):
+
+def exp(X, varX):
     """Exponentiation with error propagation"""
     Z = numpy.exp(X)
     varZ = varX * Z**2
-    return Z,varZ
+    return Z, varZ
 
-def log(X,varX):
+
+def log(X, varX):
     """Logarithm with error propagation"""
     Z = numpy.log(X)
     varZ = varX / X**2
-    return Z,varZ
+    return Z, varZ
 
 # Confirm this formula before using it
@@ -74,5 +77,6 @@
 #
 
-def pow(X,varX,n):
+
+def pow(X, varX, n):
     """X**n with error propagation"""
     # Direct algorithm
@@ -81,5 +85,5 @@
     # Indirect algorithm to minimize intermediates
     Z = X**n
-    varZ = varX/X
+    varZ = varX / X
     varZ /= X
     varZ *= Z
@@ -88,5 +92,6 @@
     return Z, varZ
 
-def div_inplace(X,varX, Y,varY):
+
+def div_inplace(X, varX, Y, varY):
     """In-place division with error propagation"""
     # Z = X/Y
@@ -98,9 +103,10 @@
     del T   # may want to use T[:] = Y for vectors
     T = Y   # reuse T for Y
-    T **=2     # T now has Y**2
+    T ** = 2     # T now has Y**2
     varX /= T  # varX now has varZ
-    return X,varX
+    return X, varX
 
-def mul_inplace(X,varX, Y,varY):
+
+def mul_inplace(X, varX, Y, varY):
     """In-place multiplication with error propagation"""
     # Z = X * Y
@@ -114,7 +120,8 @@
     varX += T  # varX now has varZ
     X *= Y     # X now has Z
-    return X,varX
+    return X, varX
 
-def sub_inplace(X,varX, Y, varY):
+
+def sub_inplace(X, varX, Y, varY):
     """In-place subtraction with error propagation"""
     # Z = X - Y
@@ -122,7 +129,8 @@
     X -= Y
     varX += varY
-    return X,varX
+    return X, varX
 
-def add_inplace(X,varX, Y,varY):
+
+def add_inplace(X, varX, Y, varY):
     """In-place addition with error propagation"""
     # Z = X + Y
@@ -130,7 +138,8 @@
     X += Y
     varX += varY
-    return X,varX
+    return X, varX
 
-def pow_inplace(X,varX,n):
+
+def pow_inplace(X, varX, n):
     """In-place X**n with error propagation"""
     # Direct algorithm
@@ -141,6 +150,6 @@
     varX /= X     # varX now has varX/X**2
     X **= n       # X now has Z = X**n
-    varX *= X     
+    varX *= X
     varX *= X     # varX now has varX/X**2 * Z**2
     varX *= n**2  # varX now has varZ
-    return X,varX
+    return X, varX
Index: sansutil/formatnum.py
===================================================================
--- sansutil/formatnum.py	(revision 402501942f1285a702e0d42b78fbaa03aae64c6d)
+++ sansutil/formatnum.py	(revision 4a96b8b36a60c2288a9134e28bbfda8a28fdca3c)
@@ -6,8 +6,8 @@
 :func:`format_uncertainty_pm`(v,err) produces the expanded format v +/- err.
 
-:func:`format_uncertainty_compact`(v,err) produces the compact format v(##), 
+:func:`format_uncertainty_compact`(v,err) produces the compact format v(##),
 where the number in parenthesis is the uncertainty in the last two digits of v.
 
-:func:`format_uncertainty`(v,err) uses the compact format by default, but this 
+:func:`format_uncertainty`(v,err) uses the compact format by default, but this
 can be changed to use the expanded +/- format by setting 
 format_uncertainty.compact to False.
@@ -34,5 +34,5 @@
     757.236 +/- 0.010
 
-UncertaintyFormatter() returns a private formatter with its own 
+UncertaintyFormatter() returns a private formatter with its own
 formatter.compact flag.
 """
@@ -62,4 +62,5 @@
 # such as 1 g/cm**3 -> 1 kg/L.
 
+
 def format_uncertainty_pm(value, uncertainty):
     """
@@ -68,21 +69,24 @@
     return _format_uncertainty(value, uncertainty, compact=False)
 
+
 def format_uncertainty_compact(value, uncertainty):
     """
     Given *value* v and *uncertainty* dv, return the compact
-    representation v(##), where ## are the first two digits of 
+    representation v(##), where ## are the first two digits of
     the uncertainty.
     """
     return _format_uncertainty(value, uncertainty, compact=True)
 
+
 class UncertaintyFormatter:
     """
     Value and uncertainty formatter.
 
-    The *formatter* instance will use either the expanded v +/- dv form 
-    or the compact v(##) form depending on whether *formatter.compact* is 
+    The *formatter* instance will use either the expanded v +/- dv form
+    or the compact v(##) form depending on whether *formatter.compact* is
     True or False.  The default is True.
     """
     compact = True
+    
     def __call__(self, value, uncertainty):
         """
@@ -92,4 +96,5 @@
 format_uncertainty = UncertaintyFormatter()
 
+
 def _format_uncertainty(value, uncertainty, compact):
     """
@@ -103,11 +108,11 @@
 
     # Handle indefinite uncertainty
-    if uncertainty is None or uncertainty<=0 or numpy.isnan(uncertainty):
-        return "%g"%value
+    if uncertainty is None or uncertainty <= 0 or numpy.isnan(uncertainty):
+        return "%g" % value
     if numpy.isinf(uncertainty):
         if compact:
-            return "%.2g(inf)"%value
+            return "%.2g(inf)" % value
         else:
-            return "%.2g +/- inf"%value
+            return "%.2g +/- inf" % value
 
     # Handle zero and negative values
@@ -125,9 +130,9 @@
         # Degenerate case: error bigger than value
         # The mantissa is 0.#(##)e#, 0.0#(##)e# or 0.00#(##)e#
-        val_place = err_place+2
+        val_place = err_place + 2
     elif err_place == val_place:
         # Degenerate case: error and value the same order of magnitude
         # The value is ##(##)e#, #.#(##)e# or 0.##(##)e#
-        val_place = err_place+1
+        val_place = err_place + 1
     elif err_place <= 1 and val_place >= -3:
         # Normal case: nice numbers and errors
@@ -140,17 +145,16 @@
     
     # Force engineering notation, with exponent a multiple of 3
-    val_place = int(math.floor(val_place/3.))*3
+    val_place = int(math.floor(val_place / 3.)) * 3
 
     # Format the result
     digits_after_decimal = abs(val_place - err_place + 1)
-    val_str = "%.*f"%(digits_after_decimal,value/10.**val_place)
-    exp_str = "e%d"%val_place if val_place != 0 else ""
+    val_str = "%.*f" % (digits_after_decimal, value / 10.**val_place)
+    exp_str = "e%d" % val_place if val_place != 0 else ""
     if compact:
-        err_str = "(%2d)"%int(uncertainty/10.**(err_place-1)+0.5)
-        result = "".join((sign,val_str,err_str,exp_str))
+        err_str = "(%2d)" % int(uncertainty / 10.**(err_place - 1) + 0.5)
+        result = "".join((sign, val_str, err_str, exp_str))
     else:
-        err_str = "%.*f"%(digits_after_decimal,uncertainty/10.**val_place)
-        result = "".join((sign,val_str,exp_str+" +/- ",err_str,exp_str))
-    #print sign,value, uncertainty, "=>", result
+        err_str = "%.*f" % (digits_after_decimal, uncertainty / 10.**val_place)
+        result = "".join((sign, val_str, exp_str + " +/- ", err_str, exp_str))
     return result
 
