Michele Simionato <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list