From 97a93932742db9e2c38672219a0aef8d1b3ad482 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 31 May 2018 17:08:29 +0100 Subject: [PATCH] tqdm.autonotebook - adds documentation and `pandas()` example (#474) - closes #443 --- README.rst | 12 ++++++++++++ tqdm/autonotebook/__init__.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tqdm/autonotebook/__init__.py diff --git a/README.rst b/README.rst index 8e25bea2..4e817ffc 100644 --- a/README.rst +++ b/README.rst @@ -665,6 +665,18 @@ light blue: no ETA); as demonstrated below. |Screenshot-Jupyter2| |Screenshot-Jupyter3| +It is also possible to let ``tqdm`` automatically choose between +console or notebook versions by using the ``autonotebook`` submodule: + +.. code:: python + + from tqdm.autonotebook import tqdm + tqdm.pandas() + +Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook +since it is not meant to be possible to distinguish between ``jupyter notebook`` +and ``jupyter console``. + Writing messages ~~~~~~~~~~~~~~~~ diff --git a/tqdm/autonotebook/__init__.py b/tqdm/autonotebook/__init__.py new file mode 100644 index 00000000..e0ba6ce2 --- /dev/null +++ b/tqdm/autonotebook/__init__.py @@ -0,0 +1,15 @@ +try: + from IPython import get_ipython + if 'IPKernelApp' not in get_ipython().config: + raise ImportError("console") +except: + from .._tqdm import tqdm, trange +else: + from .._tqdm_notebook import tqdm_notebook as tqdm + from .._tqdm_notebook import tnrange as trange + from .._tqdm import TqdmExperimentalWarning + from warnings import warn + warn("Using `tqdm.autonotebook.tqdm` in notebook mode." + " Use `tqdm.tqdm` instead to force console mode" + " (e.g. in jupyter console)", TqdmExperimentalWarning) +__all__ = ["tqdm", "trange"]