One thing I don't like about using "as" here is that with has very different semantics for that assignment than while does.<br><br>I'd rather have:<br><br>    while data in [[my_file.read(1024)]]:<br><br>
where [[...]] is a shorthand for iter(lambda: ..., None) since at least the concept of taking an expression and turning it into an iterator is fairly general. OK, that's pretty ugly so maybe I wouldn't want it. :-) If you add this to while, you're going to want this in "if" and there are lot of other cases like:<br>
<br>    while (read_a_number() as data) > 0:<br><br>I'd rather see something along the lines of PEP 315. <br><br>--- Bruce<br><br><br><div class="gmail_quote">On Thu, Jul 3, 2008 at 7:06 AM, Stavros Korokithakis <<a href="mailto:stavros@korokithakis.net">stavros@korokithakis.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello all,<br>
I have noticed that sometimes "while" loops produce "unpythonic" patterns, such as the following:<br>
<br>
data = my_file.read(1024)<br>
while data:<br>
    do_something(data)<br>
    data = my_file.read(1024)<br>
<br>
The assignment is repeated, which is less than optimal. Since we don't have a while statement that does the check in the end, would it not be better if the syntax of while could be amended to  include something like this (in the spirit of the new "with" keyword)?:<br>

<br>
while my_file.read(1024) as data:<br>
   do_something(data)<br>
<br><br></blockquote></div><br>