autonotebook.py 846 B

123456789101112131415161718192021222324252627
  1. """
  2. Automatically choose between `tqdm.notebook` and `tqdm.std`.
  3. Usage:
  4. >>> from tqdm.autonotebook import trange, tqdm
  5. >>> for i in trange(10):
  6. ... ...
  7. """
  8. import os
  9. import sys
  10. try:
  11. get_ipython = sys.modules['IPython'].get_ipython
  12. if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
  13. raise ImportError("console")
  14. if 'VSCODE_PID' in os.environ: # pragma: no cover
  15. raise ImportError("vscode")
  16. except:
  17. from .std import tqdm, trange
  18. else: # pragma: no cover
  19. from .notebook import tqdm, trange
  20. from .std import TqdmExperimentalWarning
  21. from warnings import warn
  22. warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
  23. " Use `tqdm.tqdm` instead to force console mode"
  24. " (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2)
  25. __all__ = ["tqdm", "trange"]