title: How to get filename of the __main__ module in Python?
body: <p>Suppose I have two modules:</p>
  
  <p>a.py:</p>
  
  <pre><code>import b
  print __name__, __file__
  </code></pre>
  
  <p>b.py:</p>
  
  <pre><code>print __name__, __file__
  </code></pre>
  
  <p>I run the "a.py" file. This prints:</p>
  
  <pre><code>b        C:\path\to\code\b.py
  __main__ C:\path\to\code\a.py
  </code></pre>
  
  <p><strong>Question</strong>: how do I obtain the path to the <code>__main__</code> module ("a.py" in this case) from within the "b.py" library?</p>