| Store | Cart

Question on loops

From: Daniel H Neilson <goo...@neilson.sent.com>
7 Mar 2004 17:48:49 -0800
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.

Recent Messages in this Thread
Daniel H Neilson Mar 08, 2004 01:48 am
Sean Ross Mar 08, 2004 02:35 am
Messages in this thread