title: __file__ does not exist in Jupyter Notebook
body: <p>I'm on a <a href="https://en.wikipedia.org/wiki/IPython#Project_Jupyter" rel="noreferrer">Jupyter Notebook</a> server (v4.2.2) with Python 3.4.2 and
  I want to use the global name <code>__file__</code>, because the notebook will be cloned from other users and in one section I have to run:</p>
  
  <pre><code>def __init__(self, trainingSamplesFolder='samples', maskFolder='masks'):
      self.trainingSamplesFolder = self.__getAbsPath(trainingSamplesFolder)
      self.maskFolder = self.__getAbsPath(maskFolder)
  
  def __getAbsPath(self, path):
      if os.path.isabs(path):
          return path
      else:
          return os.path.join(os.path.dirname(__file__), path)
  </code></pre>
  
  <p>The <code>__getAbsPath(self, path)</code> checks if a <code>path</code> param is a relative or absolute path and returns the absolute version of <code>path</code>. So I can use the returned <code>path</code> safely later.</p>
  
  <p>But I get the error</p>
  
  <blockquote>
    <p>NameError: name <code>'__file__'</code> is not defined</p>
  </blockquote>
  
  <p>I searched for this error online and found the "solution" that I should better use <code>sys.argv[0]</code>, but <code>print(sys.argv[0])</code> returns</p>
  
  <blockquote>
    <p><code>/usr/local/lib/python3.4/dist-packages/ipykernel/__main__.py</code></p>
  </blockquote>
  
  <p>But the correct notebook location should be <code>/home/ubuntu/notebooks/</code>.</p>
  
  <p>Thanks for the reference <em><a href="https://stackoverflow.com/questions/12544056/how-to-i-get-the-current-ipython-notebook-name">How do I get the current IPython Notebook name</a></em> from Martijn Pieters (comments) the last answer (not accepted) fits perfect for my needs:</p>
  
  <p><code>print(os.getcwd())</code></p>
  
  <blockquote>
    <p>/home/ubuntu/notebooks</p>
  </blockquote>