Q:

read through first N lines of a file in python

Typically, when reading a file, I use the for line n fileobject: construct. Is there a simple way to just loop over the first N (or some arbitrary subset) of lines in a file, so that I don't have to read in the entire file?

A:

Is this what you want:
file = open('path/to/File.txt', 'r')
for i in range(1,n):
   file.readline()

Further information is here avaliable: Python Input and Output

