Message345246
This is intended behavior.
When a variable has an assignment anywhere in a function, it becomes a local. Once a local variable exists, it will shadow the non-local variable.
So by having the "n =", you are marking "n" as a local variable. When the "n + 1" tries to read the local, it has not yet been set, so it fails.
If you want to read and write to "n" in the outer function, you will need the nonlocal statement - https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement |
|
Date |
User |
Action |
Args |
2019-06-11 15:55:10 | steve.dower | set | recipients:
+ steve.dower, paul.moore, tim.golden, zach.ware, xtreak, Mahdi Jafary |
2019-06-11 15:55:10 | steve.dower | set | messageid: <1560268510.71.0.971514532694.issue37234@roundup.psfhosted.org> |
2019-06-11 15:55:10 | steve.dower | link | issue37234 messages |
2019-06-11 15:55:10 | steve.dower | create | |
|