News for hackers. Stuff that matters.
Re:I'm Switching to Python and Actually Liking It by dec0dedab0de on Wednesday July 16, 2025 @05:03PM (#44586748)
I find it incredibly intuitive and useful that it does that. sometimes it drives me nuts that it doesn't do it for comprehensions but I can see why.

But if something fails in a loop running in the repl or jupyter I already have access to the variables.

If I want to do something with a loop of data that is roughly the same shape, I already have access to one of the the items at the end.

Short circuiting/breaking out of a loop early doesn't require an extra assignment.

I really can't see the downside.

Re:I'm Switching to Python and Actually Liking It by bobbylarrybobby on Wednesday July 16, 2025 @05:07PM (#44586777)
Python 2 actually did let comprehension variables leak out into the surrounding scope. They changed it for Python 3, presumably because it was too surprising to overwrite an existing variable with a comprehension variable.
Re:I'm Switching to Python and Actually Liking It by dapperdrake on Wednesday July 16, 2025 @11:33PM (#44589443)
That almost sounds like having the "variables" eax, ebx, ecx, and edx.
Re:I'm Switching to Python and Actually Liking It by dec0dedab0de on Thursday July 17, 2025 @10:04AM (#44593583)
Oh wow, maybe that's why I expect it to work that way! I can't believe it's been long enough since I used 2 that I'm forgetting it's quirks.