Python islice is reading the same lines
Question: I have a big log-file (> 1GB) which should be analysed, so I wrote a python-
program. I have used `islice` so I could read the file in chunks (10,000
lines) so my server won't run out of memory.

I've looked up some `islice` solutions on stackoverflow and implemented one,
but the program doesn't work as expected because isclice is reading the same
lines every time (but stops correctly after reading the whole file...). I
can't use `with open` because it comes with python 2.5, I have python 2.4...

My code looks like:

    
    
        n = 100000;     # n lines
        inf = open(fn, "r")
        while True:
            next_n_lines = list(islice(inf, n))
            if not next_n_lines:
                break
            out_fn = produce_clean_logfile(next_n_lines)
            a, t = main(out_fn)
            send_log(a,t)
    

Do you know what's wrong?

Thanks in advance. Regards, John.


Answer: 
    from itertools import islice
    n = 2;     # n lines
    fn = "myfile"
    inf = open(fn, "r")
    while True:
        next_n_lines = list(islice(inf, n))
        if not next_n_lines:
            break
        print next_n_lines
    

works for me on python 2.5, 2.6, 2.7 => I can see the lines displayed in
order.

The error certainly comes from your other functions, could you update your
question?

