[IPython-User] detect if the script is under ipython

MinRK benjaminrk@gmail....
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:

except NameError:
    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 <fperez.net@gmail.com> wrote:

> On Sun, Nov 27, 2011 at 7:21 PM, Tom Bennett <tom.bennett@mail.zyzhu.net>
> wrote:
> >
> > 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.
> Thoughts?
> f
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20111127/f57aebd7/attachment.html 

More information about the IPython-User mailing list