[IPython-dev] How to know if code is executing in a rich display (qtconsole or notebook)
MinRK
benjaminrk at gmail.com
Fri Feb 26 05:33:56 EST 2016
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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20160226/26593d1b/attachment.html>
More information about the IPython-dev
mailing list