[Python-ideas] "While" suggestion

Stavros Korokithakis stavros at korokithakis.net
Thu Jul 3 17:01:26 CEST 2008

The proposed syntax would be (mostly) equivalent to C's do ... while 
loop without adding another looping construct, so the usefulness would 
be that of do ... while. I'm not sure whether everyone considers this to 
be indispensable, but it can't be totally useless if it was included in C...

Stavros Korokithakis

Josiah Carlson wrote:
> On Thu, Jul 3, 2008 at 7:46 AM, Facundo Batista
> <facundobatista at gmail.com> wrote:
>> 2008/7/3 Stavros Korokithakis <stavros at korokithakis.net>:
>>> while my_file.read(1024) as data:
>>>   do_something(data)
>> Python explicitly disallows inline assignment ("while
>> a=myfile.read():") because of the error propensity when confusing it
>> with the comparation ("=="). But here we're gaining the same
>> advantage, without that risk.
>> So, taking into account that...
>> a) We already have "as" as an statement.
>> b) We already use "as" as an assignment [1]
>> c) This will allow more concise and intuitive code
>> ... I'm definitely +1 to this proposition.
>> In any case, Stavros, this would need a PEP...
> I would argue at a -.5.  Not every 5-line function needs to be syntax,
> and unless someone can really show a common use-case for tossing 'as'
> in the syntax of the while loop, it smells like a one-off syntax.
> Don't get me wrong, I've needed to do blocked reading before, but I
> typically write the block reader generator and call it good.
>  - Josiah
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stavros.vcf
Type: text/x-vcard
Size: 143 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080703/7e24d614/attachment.vcf>

More information about the Python-ideas mailing list