Re: guarding for StopIteration (WAS: Help with generators outside of loops.)

2004-12-08 Thread David Eppstein
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: > David Eppstein wrote: > > I've made it a policy in my own code to always surround explicit calls > > to next() with try ... except StopIteration ... guards. > > > > Otherwise if you don't guard the call and you get an u

Re: guarding for StopIteration (WAS: Help with generators outside of loops.)

2004-12-08 Thread Steven Bethard
Steven Bethard wrote: Just to clarify here, the only time code raising a StopIteration will cause a for-loop to exit silently is if the StopIteration is raised in an __iter__ method, e.g.: That was a little imprecise. What I should have said is "the only time code raising a StopIteration will c

guarding for StopIteration (WAS: Help with generators outside of loops.)

2004-12-08 Thread Steven Bethard
David Eppstein wrote: I've made it a policy in my own code to always surround explicit calls to next() with try ... except StopIteration ... guards. Otherwise if you don't guard the call and you get an unexpected exception from the next(), within a call chain that includes a for-loop over anoth