At 03:14 PM 10/21/03 -0700, Guido van Rossum wrote: >[Samuele] > > so this, if I understand: > > > > def h(): > > y = 0 > > l = [1,2] > > it = (x+y for x in l) > > y = 1 > > for v in it: > > print v > > > > will print 1,2 and not 2,3 > > > > unlike: > > > > def h(): > > y = 0 > > l = [1,2] > > def gen(S): > > for x in S: > > yield x+y > > it = gen(l) > > y = 1 > > for v in it: > > print v > >Argh. Of course. > >No, I think it should use the actual value of y, just like a nested >function. Why? >Never mind that idea then. Actually, I consider Samuele's example a good argument in *favor* of the idea. Because of the similarity between listcomps and generator expressions (gen-X's? ;) ) it seems late binding of locals would lead to people thinking the behavior is a bug. Since a genex is not a function (at least in form) a late binding would be very non-obvious and counterintuitive relative to other kinds of expressions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4