python: How do I capture a variable declared in a non global ancestral outer scope?
Given:

    def f():
      x = 0
      def g():
        h()
      def h():
        x += 1
        print(x)
      g()
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 8, in f
      File "<stdin>", line 4, in g
      File "<stdin>", line 6, in h
    UnboundLocalError: local variable 'x' referenced before assignment
    >>>

How can I make `h` see the `x` variable?

Thanks.
python: How do I capture a variable declared in a non global ancestral outer scope?
===

Given:

    def f():
      x = 0
      def g():
        h()
      def h():
        x += 1
        print(x)
      g()
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 8, in f
      File "<stdin>", line 4, in g
      File "<stdin>", line 6, in h
    UnboundLocalError: local variable 'x' referenced before assignment
    >>>

How can I make `h` see the `x` variable?

Thanks.