Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-17 Thread Stefano Borini
On Wed, 17 Apr 2019 at 00:45, Steven D'Aprano wrote: > I don't know. You tell us -- why do you care about the StopIteration > value in a for-loop? I came across the idea while I was reading various PEPs, so I don't have an actual use case under my hands right now. However, in the past I had a

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-17 Thread Stefano Borini
I don't like it either. Ideally, I would want "returning", but of course a new keyword is not an option for such limited use case. "as" is probably much better, and the behavior of as in other contexts is very similar. On Tue, 16 Apr 2019 at 23:42, Jan Kaliszewski wrote: > > Hello, > >

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Terry Reedy
On 4/16/2019 4:54 PM, Stefano Borini wrote: given the following code def g(): yield 2 yield 3 return 6 for x in g(): print(x) The output is obviously 2 3 As far as I know, there is currently no way to capture the StopIteration value when the generator is used in a for

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Greg Ewing
Jan Kaliszewski wrote: I like the idea -- occasionally (when dealing with `yield from`-intensive code...) I wish such a shortcut existed. Can you give a concrete example of a use case? -- Greg ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Steven D'Aprano
On Tue, Apr 16, 2019 at 09:54:31PM +0100, Stefano Borini wrote: > As far as I know, there is currently no way to capture the > StopIteration value when the generator is used in a for loop. Is it > true? I think you are correct. See https://bugs.python.org/issue35756 > If not, would a syntax

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Jan Kaliszewski
Hello, 2019-04-16 Stefano Borini dixit: > def g(): > yield 2 > yield 3 > return 6 [...] > for x in g() return v: > print(x) > > print(v) # prints 6 I like the idea -- occasionally (when dealing with `yield from`-intensive code...) I wish such a shortcut existed. I don't like

[Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Stefano Borini
given the following code def g(): yield 2 yield 3 return 6 for x in g(): print(x) The output is obviously 2 3 As far as I know, there is currently no way to capture the StopIteration value when the generator is used in a for loop. Is it true? If not, would a syntax like: for x