I found a probably the easiest way to find the first or last N lines of a file
Last N lines of a file(For Ex:N=10)
file=open("xyz.txt",'r")
liner=file.readlines()
for ran in range((len(liner)-N),len(liner)):
print liner[ran]
First N lines of a file(For Ex:N=10)
file=open("xyz.txt",'r")
liner=file.readlines()
for ran in range(0,N+1):
print liner[ran]