Re: How to know if code is executing in a rich display (qtconsole or notebook)
MinRK <[email protected]>
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CAHNn8BUFnm2f1N4KX5M7AexvPJHfnWTGbsO_cgtzY+an2wfYhQ@mail.gmail.com> |
You can check if it’s running in a kernel with:
try:
get_ipython().kernelexcept AttributeError:
# not a kernelelse:
# a kernel
-MinRK
On Fri, Feb 26, 2016 at 10:59 AM, Kiko <[email protected]> wrote:
> Hi all,
>
> Is there a sane way to know if some code is executing in a rich display
> environment like the qtconsole or the notebook?
>
> I think the following could work:
>
> try:
> from ipykernel.zmqshell import ZMQInteractiveShell
> ip = get_ipython()
> rich_display = isinstance(ip, ZMQInteractiveShell)
> except:
> rich_display = False
>
> Thanks!!
>
> Best.
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/ipython-dev