title: How __future__ imports work under the hood
body: <p>I've been fascinated by the <code>__future__</code> module - in particular, its ability to change the way statements are parsed in python. </p>
  
  <p>What's most interesting is how doing something like </p>
  
  <pre><code>from __future__ import print_function
  </code></pre>
  
  <p>Enables you to use <code>print</code> (and not <code>print_function</code>, like you would expect any other normal import to do).</p>
  
  <p>I have read <a href="https://stackoverflow.com/questions/7075082/what-is-future-in-python-used-for-and-how-when-to-use-it-and-how-it-works">What is __future__ in Python used for and how/when to use it, and how it works</a> thoroughly and in particular came across a particular line:</p>
  
  <blockquote>
    <p>A future statement is a directive to the compiler that a particular
    module should be compiled using syntax or semantics that will be
    available in a specified future release of Python.</p>
  </blockquote>
  
  <p>I would love to know the intricacies of what exactly makes this possible. In particular, how something like </p>
  
  <pre><code>from __future__ import division
  </code></pre>
  
  <p>Can enable true division on python2, while</p>
  
  <pre><code>from __future__ import barry_as_FLUFL
  </code></pre>
  
  <p>Can enable the <code>&lt;&gt;</code> syntax on python3 (what I find most funny is that you have to import a feature from "<code>__future__</code>" for backward compatibility).</p>
  
  <p>Anyway, to summarise, I would like to know how the directive is understood and executed by the compiler when <code>__future__</code> or its artefacts are imported. </p>