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"]