ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 27 Jan 2012 12:56:15 +0100How to if python script runs in notebook?https://ask.sagemath.org/question/8675/how-to-if-python-script-runs-in-notebook/I wrote a small piece of python code which i use as a module in python as well as in a worksheet in sage notebook.
Since this script uses pyplot i'd like to do something like
if in_notebook: pyplot.savefig('fig')
else: pyplot.show()
How can i find out where the script is running in?
At the moment i'm querying sys.executable, but i guess this can be done better.Fri, 27 Jan 2012 11:30:53 +0100https://ask.sagemath.org/question/8675/how-to-if-python-script-runs-in-notebook/Answer by Kabi for <p>I wrote a small piece of python code which i use as a module in python as well as in a worksheet in sage notebook.
Since this script uses pyplot i'd like to do something like</p>
<pre><code>if in_notebook: pyplot.savefig('fig')
else: pyplot.show()
</code></pre>
<p>How can i find out where the script is running in?</p>
<p>At the moment i'm querying sys.executable, but i guess this can be done better.</p>
https://ask.sagemath.org/question/8675/how-to-if-python-script-runs-in-notebook/?answer=13201#post-id-13201See related thread
[http://ask.sagemath.org/question/389/how-to-find-if-computation-is-in-a-notebook-or](http://ask.sagemath.org/question/389/how-to-find-if-computation-is-in-a-notebook-or)Fri, 27 Jan 2012 12:56:15 +0100https://ask.sagemath.org/question/8675/how-to-if-python-script-runs-in-notebook/?answer=13201#post-id-13201