In article
It's not really the same subject, but the exception that gives me the most grief is StopIteration. I have to keep remembering to never call .next() without catching it; if I forget, I get bugs where some loop several levels back in the call tree mysteriously exits.
Are you sure? This sounds like superstition to me, since that's not how loops work. Raising StopIteration in the middle of a loop does not break out of the loop -- only raising StopIteration from a next() breaks a loop.
Or are you talking about nested next() calls? That's the only case where the behavior you are citing occurs.
I don't remember, it could have been nested next()s. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/