Why is "while" ticking me off???
Fredrik Lundh
effbot at telia.com
Sat Oct 7 06:09:11 EDT 2000
Alan Gauld wrote:
> correct, so at the expense of typing a line twice, do
> the assignment externally:
>
> line = fp.readline()
> while line:
> # do something wiyth line
> line = fp.readline()
note that the standard pydiom (the while 1 loop) is
a refactored version of the old read-ahead pattern,
with a couple of extra advantages:
+ no code duplication
+ no need to use nested if statements to skip lines or
records; a plain continue all that's needed to get to
the next line/record.
while 1:
line = fetchline()
if end of data:
break
if empty:
continue
if comment:
continue
process line
</F>
More information about the Python-list
mailing list