[issue35725] Using for...in.. generator-iterator
Yoong Hor Meng
report at bugs.python.org
Fri Jan 11 23:26:25 EST 2019
New submission from Yoong Hor Meng <yoonghm at gmail.com>:
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 --
-- Finished --
Another things ...
I noticed that the generator function will execute whenever it is in the for...in loop. Is it expected? I do not see it documented anywhere. Thanks.
----------
components: Interpreter Core
messages: 333510
nosy: yoonghm
priority: normal
severity: normal
status: open
title: Using for...in.. generator-iterator
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35725>
_______________________________________
More information about the Python-bugs-list
mailing list