[Python-ideas] "While" suggestion
Thomas Lee
tom at vector-seven.com
Thu Jul 3 17:36:18 CEST 2008
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
More information about the Python-ideas
mailing list