[IPython-dev] Best way to detect IPython notebook
Thu Feb 20 11:17:54 CST 2014
Le 20 févr. 2014 à 17:45, TARUN GABA a écrit :
> I have written a method, which behaves differently when called from IPython notebook, and from interpreter/qtconsole respectively.
> I need to detect whether the method is called from notebook or interpreter.
> This was the code I was using till now.
> if get_ipython().config['KernelApp']['parent_appname'] == 'ipython-notebook':
> ##Do something
> But I have came to know that this particular dict changes its format in different IPython versions(I am not sure how many changes are there).
> Is there any better method to achieve this?
You should describe what you ment by "called from a notebook"
it is not clear enough to give a correct answer.
But if the question is the same as usual, and as stated in many discussion scattered
over the net and mailing list, there is no, and there will be no reliable way to detect which
frontend are requiring code execution, as there is no reason for a kernel to be connected
to only one frontend.
It is like a book writer asking "how can I make the eye color of my main character the same as my reader" ?
The question make no sense as two person can be reading the same page of the same book at the same time.
And as usual, if you describe what you are trying to archive instead of how,
you might get an answer that suit you.
> Thanks in advance :)
> IPython-dev mailing list
More information about the IPython-dev