while loop with the condition used in the body
Ulrich Eckhardt
eckhardt at satorlaser.com
Wed Feb 24 06:24:58 EST 2010
Peter Otten wrote:
> Duncan Booth wrote:
>> for rq in incoming_requests(...):
>> handle_request(rq)
>
> ...and a likely implementation would be
>
> def incoming_requests(...):
> while True:
> rq = ... # inlined version of get_request()
> if not rq:
> break
> yield rq
>
> In other words: It's turtles all the way down...
Almost. While it moves the ugliness, at least it allows separating the
iteration logic from the handling logic, which is already a big step ahead!
That said, there is:
with <expression> as <name>:
...
so why not:
while <expression> as <name>:
...
and also:
if <expression> as <name>:
...
Thanks to everybody for their input!
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list