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

Paul Rubin http
Wed Feb 18 16:33:34 EST 2004


Gerrit <gerrit at nl.linux.org> writes:
> > >     while (line := inputFile.readline()):
> > >         ...
> > > a lot better.
> 
> I disagree. I think it's counter-intuitive to have an assignment inside
> an expression. Assignments should be statements. Explicit is better than
> implicit. 

There's nothing implicit about an assignment expression.

> What problem would this solve? And why the ':'?

It solves the problem illustrated in that particular example of the
proposed new loop construction.  The := is because one of the commonly
heard objections to assigmnent expressions is that people occasionally
type "if (x = y) ..." when they meant "if (x == y)", so there's a fear
that introducing assignment expressions with just "=" will cause a lot
of program bugs.  With the colon, "if (x = y) ..." is still a syntax error.



More information about the Python-list mailing list