Exception handling in Python 3.x

Mark Wooding mdw at distorted.org.uk
Mon Dec 6 17:24:10 EST 2010


John Nagle <nagle at animats.com> writes:

> Right.  You're not entitled to assume that StopIteration is how a
> generator exits.  That's a CPyton thing; generators were a retrofit,
> and that's how they were hacked in.  Other implementations may do
> generators differently.

This is simply wrong.  The StopIteration exception is a clear part of
the generator protocol as described in 5.2.8 of the language reference;
the language reference also refers to 3.5 of the library reference,
which describes the iterator protocol (note, not the generator
implementation -- all iterators work the same way), and explicitly
mentions StopIteration as part of the protocol.

-- [mdw]



More information about the Python-list mailing list