Read multiple lines from a file batch by batch
问题 I would like to know is there a method that can read multiple lines from a file batch by batch. For example: with open(filename, 'rb') as f: for n_lines in f: process(n_lines) In this function, what I would like to do is: for every iteration, next n lines will be read from the file, batch by batch. Because one single file is too big. What I want to do is to read it part by part. 回答1: itertools.islice and two arg iter can be used to accomplish this, but it's a little funny: from itertools