title: How to tell whether a function is being called from a jupyter notebook or not?
body: <p>I'm switching a bit between Spyder and jupyter notebooks when I'm trying to learn some coding for data science. Therefore I'd like to find a way to tell whether a function is being called from one or the other so I can deactivate parts of the script that are meant for notebooks only. I thought something like the following would work to leave out the <code>%matplotlib inline</code> part when I'm running the code from Spyder:</p>
  
  <pre><code>if __name__ != '__main__':
      %matplotlib inline
      print('Hello, jupyter')
  else:
      print('Hello, Spyder')
  </code></pre>
  
  <p>But <code>__name__ = _main__</code> in both cases, and leaving <code>%matplotlib inline</code> as is also raises an error suggestion in Spyder.</p>
  
  <p>I've tested the suggestions here: <a href="https://stackoverflow.com/questions/44100477/how-to-check-if-you-are-in-a-jupyter-notebook">How to check if you are in a Jupyter notebook</a>. That works, but I am a bit puzzled since I'm running an IPython console in Spyder as well. Also, I'm hoping that some of you may have other suggestions!</p>
  
  <p>Thank you!</p>