A Python program I\'m writing is to read a set number of lines from the top of a file, and the program needs to preserve this header for future use. Currently, I\'m doing s
May be this:
header_len = 4 header = open("file.txt").readlines()[:header_len]
But, it will be troublesome for long files.