Namespacedifference reading - writing ??

Fredrik Lundh fredrik at pythonware.com
Fri Jun 27 09:13:16 EDT 2003


Peter Abel wrote:

> >>> outer()
> x in inner    =Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "<interactive input>", line 7, in outer
>   File "<interactive input>", line 4, in inner
> UnboundLocalError: local variable 'x' referenced before assignment
>
> Is there really a difference in namespacehandling depending
> on writing or reading variables?

you cannot assign to variables in an outer scope (except for the global
scope, in case you have to mark the variable as global).

the details are in the language reference:

    http://www.python.org/doc/current/ref/naming.html

</F>








More information about the Python-list mailing list