[Python-Dev] accumulator display syntax

Guido van Rossum guido at python.org
Tue Oct 21 18:14:19 EDT 2003


> >[name withheld]
> > > The implementation could synthesize a generator function abusing default
> > > arguments to give the generator's frame locals with the same names.

[Guido]
> >Yes, I think that could work -- I see no way that something invoked by
> >the generator expression could possibly modify a variable binding in
> >the surrounding scope.

[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.

Never mind that idea then.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list