Modifying a variable in a non-global outer scope?

Edward C. Jones edcjones at
Fri May 19 21:14:25 CEST 2006

#! /usr/bin/env python
When I run the following program I get the error message:

UnboundLocalError: local variable 'x' referenced before assignment

Can "inner" change the value of a variable defined in "outer"? Where
is this explained in the docs?
def outer():
     def inner():
         x = x + 1

     x = 3
     print x


More information about the Python-list mailing list