Christopher Lemmer Webber is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.

I guess when I considered myself a Pythonista I didn't ever notice how bonkers Python's scoping is

@Thib I haven't run into weird issues with list comprehension, but maybe if I looked again I'd realize them. But I think you could mostly do something with a list comprehension like interface using macros and lexical scope.

locals/globals though, what a weird design

@cwebber in Python 2, variables defined in list comprehensions escaped their scope, this has been fixed in Python 3.

e.g.,
foo = [x * y for x, y in enumerate(bar)]

would leak x and y in the remaining code

Christopher Lemmer Webber @cwebber

@Thib Still true with for loops

>>> def foo():
... bar = "baz"
... for i in "beep":
... bar = i
... return bar
...
>>> foo()
'p'

· Web · 0 · 0

@cwebber @Thib for me as for person who always lived in C-like languages, this looks perfectly fine and expected.