[issue12023] non causal behavior

2011-05-07 Thread R. David Murray
R. David Murray added the comment: In 3.x, yes (the nonlocal keyword). Not in 2.7, though. -- nosy: +r.david.murray ___ Python tracker ___ _

[issue12023] non causal behavior

2011-05-06 Thread Rodrigo Ventura
Rodrigo Ventura added the comment: Ezio, thank you for the explanation. Is it possible to access variable a in nok's scope from function f without using the global keyword in f? (so that variable a remains local to nok, rather than global to python) Rodrigo --

[issue12023] non causal behavior

2011-05-06 Thread Ezio Melotti
Ezio Melotti added the comment: See also http://docs.python.org/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value -- ___ Python tracker _

[issue12023] non causal behavior

2011-05-06 Thread Ezio Melotti
Ezio Melotti added the comment: The reason is that in nok Python sees the assignment to a (a = 1) and determines that the 'a' variable is local to the scope of f, and since the assignment comes after the "if a:" and at that point 'a' has no value, an error is raised. In ok there's no assignme

[issue12023] non causal behavior

2011-05-06 Thread Rodrigo Ventura
New submission from Rodrigo Ventura : Consider these two functions: --- def nok(): a = None def f(): if a: a = 1 f() def ok(): a = None def f(): if a: b = 1 f() --- Function ok() executes fine, but function nok() trigger an excepti