Skip to content

Instantly share code, notes, and snippets.

@y1zhou
Created July 24, 2018 18:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save y1zhou/ba9318ba819568fe2fa3466f5e373b96 to your computer and use it in GitHub Desktop.
Save y1zhou/ba9318ba819568fe2fa3466f5e373b96 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