Skip to content

Commit 97a9393

Browse files
committed
tqdm.autonotebook
- adds documentation and `pandas()` example (#474) - closes #443
1 parent 0307fd1 commit 97a9393

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,18 @@ light blue: no ETA); as demonstrated below.
665665
|Screenshot-Jupyter2|
666666
|Screenshot-Jupyter3|
667667

668+
It is also possible to let ``tqdm`` automatically choose between
669+
console or notebook versions by using the ``autonotebook`` submodule:
670+
671+
.. code:: python
672+
673+
from tqdm.autonotebook import tqdm
674+
tqdm.pandas()
675+
676+
Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
677+
since it is not meant to be possible to distinguish between ``jupyter notebook``
678+
and ``jupyter console``.
679+
668680
Writing messages
669681
~~~~~~~~~~~~~~~~
670682

tqdm/autonotebook/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
try:
2+
from IPython import get_ipython
3+
if 'IPKernelApp' not in get_ipython().config:
4+
raise ImportError("console")
5+
except:
6+
from .._tqdm import tqdm, trange
7+
else:
8+
from .._tqdm_notebook import tqdm_notebook as tqdm
9+
from .._tqdm_notebook import tnrange as trange
10+
from .._tqdm import TqdmExperimentalWarning
11+
from warnings import warn
12+
warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
13+
" Use `tqdm.tqdm` instead to force console mode"
14+
" (e.g. in jupyter console)", TqdmExperimentalWarning)
15+
__all__ = ["tqdm", "trange"]

0 commit comments

Comments
 (0)