[Python-ideas] "While" suggestion

Stavros Korokithakis stavros at korokithakis.net
Thu Jul 3 17:44:59 CEST 2008


That is true, but in this particular usage there's no iterator that 
would do what we wanted... I agree that it approaches the realm of the 
"for" statement, though.

Stavros

Thomas Lee wrote:
> Facundo Batista wrote:
>> 2008/7/3 George Sakkis <george.sakkis at gmail.com>:
>>
>>  
>>> There is already an idiom for this, although admittedly not obvious or
>>> well-known:
>>>
>>> for data in iter(lambda: my_file.read(1024), ''):
>>>     do_something(data)
>>>
>>> or in 2.5+:
>>>
>>> from functools import partial
>>> for data in iter(partial(my_file.read,1024), ''):
>>>     do_something(data)
>>>     
>>
>> Yes, but note that these feels like workarounds.
>>
>> One thing that I love in Python is that you can learn a concept, and
>> apply it a lot of times.
>>
>> So, suppose I'm learning Python and find that I can do this...
>>
>>   with_stmt ::=  "with" expression ["as" target] ":" suite
>>
>> ...why can't I do this?:
>>
>>   while_stmt ::=  "while" expression ["as" target]  ":" suite
>>
>>   
> I'm -1on the while .. as syntax myself.
> 
> Something about this syntax feels wrong ... it's effectively a for loop 
> looking for a reason not to use an iterator.
> 
> You might be right about it being more consistent though.
> 
> Cheers,
> T
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- 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/90dff1c8/attachment.vcf>


More information about the Python-ideas mailing list