readfile - Python islice is reading the same lines -
i have big log-file (> 1gb) should analysed, wrote python-program. have used islice
read file in chunks (10,000 lines) server won't run out of memory.
i've looked islice
solutions on stackoverflow , implemented one, program doesn't work expected because isclice reading same lines every time (but stops correctly after reading whole file...). can't use with open
because comes python 2.5, 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 know what's wrong?
thanks in advance. regards, john.
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 me on python 2.5, 2.6, 2.7 => can see lines displayed in order.
the error comes other functions, update question?
Comments
Post a Comment