from __future__ import nested_scopes
def foo(): x = 1 def bar(): print x # Use of nonlocal variable while x < 10: bar() x += 1