Reading every 100 lines (or less) from an open file in Python -



Reading every 100 lines (or less) from an open file in Python -

i have file 100s of thousands of records, 1 per line. need read 100, process them, read 100, process them , forth. don't want load many records , maintain them in memory. how read (until eof) either 100 or less (when eof encountered) lines open file using python?

islice() can used retrieve next n items of iterator.

from itertools import islice open(...) file: while true: lines = list(islice(file, 100)) line in lines: # stuff if not lines: break

python

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -