[Python-ideas] "While" suggestion
Leif Walsh
leif.walsh at gmail.com
Thu Jul 3 19:57:39 CEST 2008
I am against while...as syntax for a reason given above (doesn't map
to an english statement nearly as well as with...as does).
Besides, you can write much clearer code by making yourself a
generator somewhere else that does the nasty bits, and then using a
for loop to actually consume the data, like you should:
def kilogenerator(file):
while True:
try:
yield file.read(1024)
except EOFError: # or whatever
return
for kilo in kilogenerator(myfile):
process(kilo)
--
Cheers,
Leif
More information about the Python-ideas
mailing list