Feature Proposal: Sequence .join method

Alex Martelli aleax at mail.comcast.net
Sat Oct 8 08:17:37 EDT 2005


Michele Simionato <michele.simionato at gmail.com> wrote:
   ...
> I have noticed a while ago that inside generators StopIteration is
> automatically trapped, i.e.
> 
> def g():
>     yield 1
>     raise StopIteration
>     yield "Never reached"
> 
> only yields 1. Not sure if this is documented behavior, however, of if
> it is an implementation
> accident. Anybody who knows?

It yields 1 and on the next call to .next() raises StopIteration, which
is the way an iterator says it's done -- so, it yields 1 and then it's
done.  I'm not sure what you mean by "inside generators ...
automatically trapped", or what's undocumented about that.


Alex



More information about the Python-list mailing list