title: Accessing a Variable from Within a Doubly Nested Function in Python
body: <p>The following code:</p>
  
  <pre><code>x = 0
  print "Initialization: ", x
  def f1():
      x = 1
      print "In f1 before f2:", x
      def f2():
          global x
          x = 2
          print "In f2:          ", x
      f2()
      print "In f1 after f2: ", x
  f1()
  print "Final:          ", x
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>Initialization:  0
  In f1 before f2: 1
  In f2:           2
  In f1 after f2:  1
  Final:           2
  </code></pre>
  
  <p>Is there a way for <code>f2</code> to access <code>f1</code>'s variables?</p>