4 ms·
> not knowing that Python does not do block-level variable scoping, so loop variables leak For what it's worth, it took me a long time to internalize this (mor
by eslaught 4y ago
> not knowing that Python does not do block-level variable scoping, so loop variables leak
For what it's worth, it took me a long time to internalize this (more than ten years after first learning Python), I think partly because the way most people teach Python is to say what scopes Python has instead of saying what scopes it doesn't have. While it's bad style to abuse this, I would definitely consider this a part of Python that a lot of working developers probably don't understand well.
- d0mine 4y agoYes. Scopes are complicated e.g., class Foo: a = [1,2,3] b = [4,5,6] c = [x * y for x in a for y in b] that leads to NameError: name 'b' is not defined https://bugs.python.org/issue3692 https://bugs.python.org/issue3692