Meta: PEP discussion (was Re: PEP 255: Simple Generators)
Just van Rossum
just at letterror.com
Wed Jun 27 11:16:00 CEST 2001
Robin Becker wrote:
> it would have been so much nicer and easier if these generator functions
> could be generalised to be resumable then all the nonsense about where
> and when they could be used would vanish. This seems to be too late now.
Eh? This *is* generalized: you can resume a generator "by hand":
>>> def gen(x):
... i = 0
... while i < x:
... yield i
... i += 1
>>> g = gen(4)
Traceback (most recent call last):
File "<input>", line 1, in ?
The fact that this uses the iterator protocol is merely because it's practical:
most often generators will be used in a for context.
More information about the Python-list