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


Groups > comp.lang.python > #32069 > unrolled thread

Re: while expression feature proposal

Started byTim Chase <python.list@tim.thechases.com>
First post2012-10-24 16:54 -0500
Last post2012-10-24 16:54 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#32069 — Re: while expression feature proposal

FromTim Chase <python.list@tim.thechases.com>
Date2012-10-24 16:54 -0500
SubjectRe: while expression feature proposal
Message-ID<mailman.2798.1351115620.27098.python-list@python.org>
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





[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web