title: "from __future__ imports must occur at the beginning of the file": what defines the beginning of the file?
body: <p>The Python  script</p>
  
  <pre><code>'''
  a
  '''
  
  from __future__ import print_function
  </code></pre>
  
  <p>works well (i.e., does nothing), but</p>
  
  <pre><code>'''
  a
  '''
  
  '''
  b
  '''
  from __future__ import print_function
  </code></pre>
  
  <p>causes:  </p>
  
  <pre><code>File "C:\test.py", line 8
      from __future__ import print_function
  SyntaxError: from __future__ imports must occur at the beginning of the file
  </code></pre>
  
  <p>Why? </p>
  
  <hr>
  
  <p><a href="https://docs.python.org/2/reference/simple_stmts.html#future" rel="noreferrer">https://docs.python.org/2/reference/simple_stmts.html#future</a> says that:</p>
  
  <blockquote>
    <p>A future statement must appear near the top of the module. The only
    lines that can appear before a future statement are:</p>
    
    <ul>
    <li>the module docstring (if any),</li>
    <li><strong>comments</strong>,</li>
    <li><strong>blank lines</strong>, and</li>
    <li>other future statements.</li>
    </ul>
  </blockquote>
  
  <p>The second example only contains comments and blank lines before the <code>from __future__ import print_function</code>, and yet it doesn't work.</p>
  
  <p>I use Python 2.7.</p>