Re: How to know if code is executing in a rich display (qtconsole or notebook)

Kiko <[email protected]>
Newsgroups gmane.comp.python.ipython.devel
Message-ID <CAB-sx627grgnw9N+u0q=hJYnyaQVYmLaQz1svScLTPcWnDLTnQ@mail.gmail.com>
Thanks!!

2016-02-26 11:33 GMT+01:00 MinRK <[email protected]>:

> 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
>
>

_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/ipython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.