Question on loops

Daniel H Neilson google at neilson.sent.com
Sun Mar 7 20:48:49 EST 2004


I am a newcomer to python, and am not really much more than a hack at
the other languages I speak, so forgive me if this is an easy
question.

I am processing a text file, taking an action based on what I find in
each line. Independently of what the file contains, I need to take
another action every 100 lines. Currently I am using something to the
effect of:

i = 0
for line in file:
    if i == 100:
        action
        i = 0
    else:
        i += 1
    process(line)

But this doesn't feel like a very python-esque solution to me, and is
not very elegant in any case. What would be a better way to do it?

Thanks.



More information about the Python-list mailing list