Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created August 30, 2019 07:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/e5e2da71ea3ee412616b27d364e3ae82 to your computer and use it in GitHub Desktop.
Save thomasaarholt/e5e2da71ea3ee412616b27d364e3ae82 to your computer and use it in GitHub Desktop.
Check if code is running in jupyter notebook
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