Say I have the following file t.py:
from IPython import get_ipython
if __name__ == '__main__':
ip = get_ipython()
if ip is not None:
print('Found IPython')
Here's what happens if I run it, with both Python and IPython:
% python t.py
% ipython t.py
Found IPython
Note that, only when running it with ipython, is get_ipython() not None.
Is there a way to start an IPython kernel from within the script, so that even if I run it as python t.py, then get_ipython() will not be None?