title: Scope of variables in function factories
body: <p>I was wondering about the scope of the variable <code>a</code> in the following Python snippet,</p>
  
  <pre class="lang-py prettyprint-override"><code># ============================
  def get_plotter():
      def get_a():
          return a
      a = 3.14
      return get_a
  # ============================
  if __name__ == '__main__':
      f = get_plotter()
      print f()
  # ============================
  </code></pre>
  
  <p>The output is <code>3.14</code>, but looking at the code I would have expected <code>a</code> to go out of scope as soon as <code>get_plotter()</code> terminates, effectively leaving an undefined something.</p>
  
  <p>Is it just volatile memory contents that are printed here? What's going on?</p>