Commits

yanchuan sim committed d69519e

added default to stdout and big/small interval for progress

  • Participants
  • Parent commits 54df4f4

Comments (0)

Files changed (1)

File ycutils/misc.py

 .. autofunction:: progress
 """
 
-def progress(i, interval=5, wait_char='.', write_to=None):
+import sys
+
+def progress(i, interval=(1, 5), wait_char='.', write_to=sys.stderr):
   """ Useful for displaying a progress update.
 
   :param i: the current display index.
   :param interval: how often to display a numerical update instead of :attr:`wait_char`.
-  :param write_to: specifies which stream to write updates to. Defaults to ``None``.
+  :param write_to: specifies which stream to write updates to. Defaults to :attr:`sys.stderr`.
   :returns: a :attr:`wait_char` (defaults to ``.``) or a number (every :attr:`interval` updates).
   :rtype: string.
   """
 
-  if i % interval == 0:
+  if i % interval[1] == 0 or i <= 1:
     if write_to: write_to.write(str(i))
     return str(i)
   #end if
 
-  if write_to: write_to.write(wait_char)
-  return wait_char
+  if i % interval[0] == 0:
+    write_to.write(wait_char)
+    return wait_char
+  #end if
+  
+  return None
 #end def