title: Why os.path.dirname(__file__) is working in Django?
body: <p>Please explain why <code>os.path.dirname(__file__)</code> is working in Django, but not working in python?
  This is kind of weird situation which I can't understand.</p>
  
  <p>I made a python script and put it in a file test_file.py:</p>
  
  <pre><code>import os
  
  dirname = os.path.dirname(os.path.dirname(__file__))
  realpath = os.path.dirname(os.path.realpath(__file__))
  abspath = os.path.dirname(os.path.abspath(__file__))
  
  print dirname
  print realpath
  print abspath
  </code></pre>
  
  <p>When I run the script, I get results:</p>
  
  <pre><code>(env)user@ubuntubox:~/srv/django_pro$ python test_file.py 
  
  /home/srv/django_pro
  /home/srv/django_pro
  (env)user@ubuntubox:~/srv/django_pro$
  </code></pre>
  
  <p>I get results that <strong>realpath</strong> and <strong>abspath</strong> are working, but <strong>dirname</strong> is empty. However in Django settings.py I have:</p>
  
  <pre><code>BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  </code></pre>
  
  <p>If I go into python shell and print out BASE_DIR, it is not empty:</p>
  
  <pre><code>(env)user@ubuntubox:~/srv/django_pro$ python manage.py shell
  Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
  [GCC 4.8.2] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  (InteractiveConsole)
  &gt;&gt;&gt; from django.conf import settings
  &gt;&gt;&gt; 
  &gt;&gt;&gt; print 'BASE_DIR:\n%s' % settings.BASE_DIR
  BASE_DIR:
  /home/srv/django_pro
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>And that means os.path.dirname(os.path.dirname(<strong>file</strong>)) is not empty. I am using same python in both cases. And my Django version is:</p>
  
  <pre><code>Django==1.7b4
  </code></pre>
  
  <p>So what is the trick?</p>