Find out if Code is Run in Notebook
M-Colley opened this issue · 1 comments
M-Colley commented
Hey,
you have defined
def IsNotebook():
try:
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
However, when running PhySO in Google Colab, this returns false.
You could enhance the method such as:
def IsNotebook():
try:
if 'google.colab' in str(get_ipython()):
return True # Google Colab
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
With this being new:
if 'google.colab' in str(get_ipython()):
return True # Google Colab
WassimTenachi commented
Thank you very much for this snippet of code !
If you want you to take credit you can contribute it yourself otherwise I will add it shortly !
Cheers.
Wassim