for-else
castironpi at gmail.com
castironpi at gmail.com
Tue Mar 4 21:47:17 EST 2008
That you could do yourself, CMIIW correct me if I'm wrong.
try:
for foo in iterex( bar_sequence ):
> # normal iteration
> spam(foo)
> if funky(foo):
> break
except StopIterationEx, exc:
> # the iterator stopped normally
> eggs(exc)
> else:
> # the iterator exited abnormally, i.e. 'break'
> sausage()
> finally:
> # always executed, even on 'break'
> beans()
Qualm, except would be needed in every for-, and in one sense doesn't
obey the semantics of exceptions. The end of a finite list is not an
exceptional element-- it's not one. However generator semantics don't
yield finite sequences-- and finity is an exception, but for-loops
don't use infinite ones.
Makes it sound (*subj've) like I'm hacking by using for-loops..... or,
like sequencetype.__iter__ is malformed. <staggered diminished chord>
More information about the Python-list
mailing list