Hacker News new | past | comments | ask | show | jobs | submit login

You may need to add a 'global' statement or something similiar. If you are going to mutate a variable in a function Python assumes that you want to create a new variable in that scope.

Generally I do not mutate variables as far as possible, so I have not hit this problem myself, yet. Perhaps there is someone more knowledgeable about Python to step in.




But it's not a global variable, it's scoped within the closure. So, this means Python doesn't have lexical scoping?


It has. Just the syntax was a bit awkward when modifying variables of higher scope. See sibling comment.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: