Update documentation, per-file refresh

This commit is contained in:
Casper da Costa-Luis 2016-01-31 20:29:05 +01:00
parent 3567a90427
commit a483e55e3f
2 changed files with 41 additions and 1 deletions

View File

@ -315,6 +315,21 @@ Returns
Cleanup and (if leave=False) close the progressbar.
"""
def clear(self):
"""
Clear current bar display
"""
def refresh(self):
"""
Force refresh the display of this bar
"""
def write(cls, s, file=sys.stdout, end="\n"):
"""
Print a message via tqdm (without overlap with bars)
"""
def trange(*args, **kwargs):
"""
A shortcut for tqdm(xrange(*args), **kwargs).
@ -449,6 +464,30 @@ For manual control over positioning (e.g. for multi-threaded use),
you may specify `position=n` where `n=0` for the outermost bar,
`n=1` for the next, and so on.
Writing messages
~~~~~~~~~~~~~~~~~~~~
Since ``tqdm`` uses a simple printing mechanism to display progress bars,
you should not write any message in the terminal using ``print()``.
To write messages in the terminal without any collision with ``tqdm`` bar
display, a ``.write()`` method is provided:
.. code:: python
from tqdm import tqdm, trange
from time import sleep
bar = trange(10)
for i in bar:
# Print using tqdm class method .write()
sleep(0.1)
if not (i % 3):
tqdm.write("Done task %i" % i)
# Can also use bar.write()
By default, this will print to standard output ``sys.stdout``. but you can
specify any file-like object using the ``file`` argument. For example, this
can be used to redirect the messages writing to a log file or class.
How to make a good progress bar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -292,7 +292,8 @@ class tqdm(object):
"""
# Clear all bars
for inst in cls._instances:
inst.clear()
if inst.fp == file:
inst.clear()
# Write the message
file.write(s)
file.write(end)