Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32069

Re: while expression feature proposal

Date 2012-10-24 16:54 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: while expression feature proposal
References <CAOKWLrERVuT-u=9YZGnQUhWLv2M6F06pU20vG9W1joD9h-SdSQ@mail.gmail.com> <CALwzidm1zj5ZR4YU-DCWBgY3Q4m=UC0BNs3qJfwYpV+Kh+21cg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2798.1351115620.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/24/12 16:34, Ian Kelly wrote:
> On Wed, Oct 24, 2012 at 2:40 PM, Dan Loewenherz <dloewenherz@gmail.com> wrote:
>> So I'm sure a lot of you have run into the following pattern. I use it
>> all the time and it always has felt a bit awkward due to the duplicate
>> variable assignment.
>>
>> VAR = EXPR
>> while VAR:
>>     BLOCK
>>     VAR = EXPR
> 
> The idiomatic way to do this is:
> 
> while True:
>     VAR = EXPR
>     if not VAR:
>         break
>     BLOCK

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.

-tkc





Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: while expression feature proposal Tim Chase <python.list@tim.thechases.com> - 2012-10-24 16:54 -0500

csiph-web