Conditional Expressions don't solve the problem

Andrew Dalke dalke at dalkescientific.com
Tue Oct 16 13:19:22 EDT 2001


Dale Strickland-Clark wrote:
>I think this is verbose. I would much prefer be able to write:
>
>while term := self.nextTerm():
>    for a in argObjects:
>        if handled := a.test(term):
>             break
>    if not handled:
>        raise whatever

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






More information about the Python-list mailing list