Re:Pattern matching accepted for Python
by pfalcon on Wednesday February 10, 2021 @06:00AM
(#26087689)
Right. But the whole idea of Python scoping rules was to not burden people with the need to declare variables (instead, if you define one, it's accessible everywhere in the function).
But yes, block-level scoping (as in C for example) would be useful too in addition to existing whole-function scoping discipline.
Again, I'm looking for similarly-minded people to move this idea forward. If interested, please find me on the python-ideas mailing list for discussing details.
In the general case, you just declare the variable in the surrounding scope and then affect it in the lower one, no?