while expression feature proposal

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 24 18:54:14 EDT 2012


On Wed, Oct 24, 2012 at 3:54 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
> It may be idiomatic, but that doesn't stop it from being pretty
> ugly.  I must say I really like the parity of Dan's
>
>   while EXPR as VAR:
>      BLOCK
>
> proposal with the "with" statement.  It also doesn't fall prey to
> the "mistaken-assignment vs. intentional-assignment" found in most
> C-like languages.  I could see a pretty reasonable PEP coming from this.

Often though the while test is not a simple boolean test of VAR.  For example:

j = int(random() * n)
while j in selected:
    j = int(random() * n)

It also doesn't flow quite as naturally.  "with x as y" is
grammatically correct English.  "while x as y" is not, and I wonder
how easily it might be confused for "while x is y", which is valid
Python and means something completely different.



More information about the Python-list mailing list