PEP 255: Simple Generators

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Jun 20 02:21:42 EDT 2001


Carsten Geckeler wrote:
> 
> But I have to rely that a single "return" raises a StopIter exception when
> I want to catch it.

You don't have to catch it -- the for-loop implementation
does that.

This part of the proposal is exactly right, IMO --
the generator uses "yield" to produce values, and
returns normally when it has finished. Any exceptions
involved are an implementation detail, hidden behind
the scenes.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list