[IPython-User] detect if the script is under ipython
Mon Nov 28 00:22:48 CST 2011
There are two ways that work in 0.11 and after:
if the name `get_ipython` exists, you are in IPython:
in_ipython = False
in_ipython = True
get_ipython() will return the current IPython instance, if you have cause
to query/manipulate it.
More programmatically, you can check if an InteractiveShell exists:
from IPython.core.interactiveshell import InteractiveShell
in_ipython = InteractiveShell.initialized()
On Sun, Nov 27, 2011 at 19:29, Fernando Perez <email@example.com> wrote:
> On Sun, Nov 27, 2011 at 7:21 PM, Tom Bennett <firstname.lastname@example.org>
> > I am wondering if there is a way to detect if a script is under ipython
> > 0.12. __IPYTHON__ no longer works.
> Sorry about that... There is now a numerical flag, __IPYTHON__active,
> that you can test for. It tries to count the levels of nesting of
> IPython, but honestly I think that in the long run we should go for
> something much simpler: just a flag, called __IPYTHON__ whose presence
> indicates IPython is active and that we delete when we exit. Since
> now we have not only terminal interaction but also event-driven
> kernels (on zmq), I think it's a bit hopeless to try to track levels
> of nesting correctly. A very simple flag, set in the builtins when
> the object is initialized, is probably all we should have. Anything
> else is bound to be brittle and likely to hurt more than it helps.
> IPython-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User