Created
August 30, 2019 07:02
-
-
Save thomasaarholt/e5e2da71ea3ee412616b27d364e3ae82 to your computer and use it in GitHub Desktop.
Check if code is running in jupyter notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_notebook(): | |
try: | |
from IPython import get_ipython | |
if "IPKernelApp" not in get_ipython().config: # pragma: no cover | |
raise ImportError("console") | |
return False | |
if "VSCODE_PID" in os.environ: # pragma: no cover | |
raise ImportError("vscode") | |
return False | |
except: | |
return False | |
else: # pragma: no cover | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment