This is why in Python, assignment is a declaration of a local variable by default, you have to mark it as "global" (or "nonlocal" in Python 3), if you want to refer to a global.
I actually kind of hate the python scoping. Since the lexical scoping is so limited ("nonlocal" is a verbose hack) everyone ends up using big classes and explicit self dictionaries instead. Automatic variable declaration also means that typos get turned into new variables instead of errors.
View all comments
2
u/[deleted] Jul 26 '13
This is why in Python, assignment is a declaration of a local variable by default, you have to mark it as "global" (or "nonlocal" in Python 3), if you want to refer to a global.