[IPython-dev] How to know if code is executing in a rich display (qtconsole or notebook)

Kiko kikocorreoso at gmail.com
Fri Feb 26 05:38:14 EST 2016


Thanks!!

2016-02-26 11:33 GMT+01:00 MinRK <benjaminrk at 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 <kikocorreoso at gmail.com> 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
>> IPython-dev at scipy.org
>> https://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20160226/85c43450/attachment.html>


More information about the IPython-dev mailing list