Skip to content

Instantly share code, notes, and snippets.

@AllenCoder
Forked from y1zhou/read_n_lines.py
Created July 25, 2018 01:38
Show Gist options
  • Save AllenCoder/7f1270c45393068df8394da49ad926d0 to your computer and use it in GitHub Desktop.
Save AllenCoder/7f1270c45393068df8394da49ad926d0 to your computer and use it in GitHub Desktop.
from itertools import islice
def next_n_lines(file_opened, N):
return [x.strip() for x in islice(file_opened, N)]
with open("samplefile", 'r') as f:
x = ""
while x != []:
x = next_n_lines(f, 5) # returns a list
pass # do something to x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment