You cannot determine if you are in an IPython laptop or qtconsole or in a simple IPython shell, for the simple reason that 3 can be connected to the same kernel at the same time.
It will be like asking what color is the current key that the user enters. You can get it by looking at the connected USB devices and look at the images on the Internet and guess the color of the keyboard, but nothing guarantees that it will be accurate and that it will not change, and the user can connect several keyboards or even a painted keyboard.
This is really the same with a notebook. Even if you determine that you are in ZMQKernel, are you browsing qtconsole or a web server? Again, you find yourself talking to a web server, are you talking to JS or Emacs? And so on and so forth.
The only thing you can do is ask the user.
What is reliable is the test that you use in IPython or not.
If you really , but reeaaalllyy want a way, since still a laptop is the only thing that Javascript can display. And javascript can execute code in pyton. That way, you could be able to create something that displays JSs that send information back to the kernel. And using a thread and a timer, you can say that you were not in the laptop (but you will have a race condition).
Matt
source share