[issue35725] Using for...in.. generator-iterator

2019-01-11 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I was also typing a similar reply and Steve explained it better :) Just to add there is a note on implicit next call on a for loop in the documentation. https://docs.python.org/3/reference/expressions.html#generator.__next__ > Starts the execution o

[issue35725] Using for...in.. generator-iterator

2019-01-11 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, it is standard behaviour for all iterators, not just generators. For loops work by calling next() on the iterator object, if you call next() on the same object inside the loop, that has the effect of advancing the for loop. You say: > I

[issue35725] Using for...in.. generator-iterator

2019-01-11 Thread Yoong Hor Meng
New submission from Yoong Hor Meng : def f(): print('-- Start --') yield 1 print('-- Middle --') yield 2 print('-- Finished --') yield 3 gen = f() for x in gen: print('Another things ...') next(gen) The output: -- Start -- Another things ... -- Middle -- -- Fi