PEP 318

Greg Ewing (using news.cis.dfn.de) ieyf4fu02 at sneakemail.com
Wed Mar 24 01:03:48 EST 2004


Eyal Lotem wrote:
> You are not supposed to be looking for it, IMHO.
> Generators follow the Sequence protocol and are to be
> treated as sequences.  Thus, you should simply make it
> clear in the
> function-name/conventions/interface-documentation that
> the function returns a sequence.  Whether that
> sequence is implemented via a generator or not is an
> implementation detail.

That may be true when you're *using* the generator, but
when looking at the implementation, it can be helpful
if you're warned ahead of time that you're wading into
generator code, to get you into the right frame of
mind.

I had that experience just the other day -- started
reading a function, had some moments of wondering
"how does this work?", then thought "oh, I know, I
bet this is a generator"... skimmed through it, and
sure enough, there was a 'yield'.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list