[Python-Dev] PEP 3142: Add a "while" clause to generator expressions

Russell E. Owen rowen at u.washington.edu
Wed Jan 21 20:47:52 CET 2009


In article <Pine.LNX.4.64.0901210811430.14037 at kimball.webabinitio.net>,
 rdmurray at bitdance.com wrote:

>...
> I understand that you are saying that 'while x' is used in the same
> logical sense ("take a different action when x is no longer true"),
> but that I don't feel that that is enough to say that it has similar
> semantics.  Or, perhaps more accurately, it is just similar enough to be
> very confusing because it is also different enough to be very surprising.
> The semantics of 'while' in python includes the bit about creating a
> loop, and does _not_ include executing a 'break' in the surrounding loop.
> To give 'while' this new meaning would be, IMO, un-pythonic.  (If python
> had a 'for/while' construct, it would be a different story...and then
> it would probably already be part of the list comprehension syntax.)

I agree. I feel that the term "while" is a poor choice for "when this is 
no longer true then stop". It sounds more like a synonym for "if" to me.

I would be much more comfortable using "until" (in the opposite sense to 
the proposed "while"); it clearly implies "we're done so stop". I don't 
know if it's a feature that is really useful, but I do think it would be 
transparent: code that used it would be easily understood.

-- Russell



More information about the Python-Dev mailing list