PEP-0315--Enhanced While Loop: An idea for an alternative syntax

Andrew Koenig ark at acm.org
Wed Feb 18 09:01:44 EST 2004


"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7xwu6khofz.fsf at ruckus.brouhaha.com...
> Erik Max Francis <max at alcyone.com> writes:
> > do:
> >     line = inputFile.readline()
> > while line:
> >     ...
> >     line = inputFile.readline()
>
> So it's yet another workaround for Python's lack of assignment
> expressions.  I like
>
>     while (line := inputFile.readline()):
>         ...
>
> a lot better.

I don't, because it limits what is done before the test to a single
expression.

This PEP is really a generalization of the "while (cond) expr" and "do expr
while(cond);" statements in C.  C allows the loop exit to be one expression
away from the beginning or one expression away from the end of the loop;
this PEP would allow it anywhere.





More information about the Python-list mailing list