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-sx60PhOzs_v5KJFmR_B6qLp6dVmozqy4msAknCM-4Yb4zWQ@mail.gmail.com>
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
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.