Amaury Forgeot d'Arc added the comment:
What fails here is the evaluation of "x", not the assignment!
You are right concerning the assignment, the outer definition has no effect at
all. The very presence of "x = " in the function code turns x into a local
variable for the whole function; so
Frederick Ross added the comment:
Assignment in Python creates a new binding. Whether the new binding shadows or
replaces an old binding should be irrelevant. This behavior is inconsistent
with that. Please fix expectations, and then Python interpreter.
--
resolution: invalid ->
stat
Amaury Forgeot d'Arc added the comment:
This is expected behavior:
http://docs.python.org/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value
--
nosy: +amaury.forgeotdarc
resolution: -> invalid
status: open -> closed
__
New submission from Frederick Ross :
The following code throws an UnboundLocal error:
def f(x):
def g():
x = x + "a"
return x
return g()
f("b")
--
components: None
messages: 161432
nosy: Frederick.Ross
priority: normal
severity: normal
status: open
title: An erro