Conditional Expressions don't solve the problem

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Tue Oct 16 18:40:45 EDT 2001


"Andrew Dalke" <dalke at dalkescientific.com> wrote:

>Wouldn't you prefer (in Python 2.2)
>
>for term in iter(self.nextTerm, None):
>    for a in argObjects:
>        if a.test(term):
>            break
>    else:
>        raise whatever
>
>Same number of lines.  No need for ':='.  No ugly flag
>variables.  Very Pythonic.
>
>                    Andrew
>                    dalke at dalkescientific.com

That looks OK. Somehow for/else had eluded me but I'm using it now.
Thanks for that.

Having not seen this before, I'm a bit surprised at the choice of the
word 'else' here. It's not an alternative. It's a conclusion. I would
have thought 'then' or 'finally' would have been more appropriate.

A bit late now, I guess.

Is iter just an extra object layer to map the interface. Will it be an
overhead?


--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list