Hi, newbie here, sorry. I have a couple of basic Python questions.
1) How do I open 'datafile' and skip to the ith line for reading? I have a loop counter i for this purpose. The data file is very long, and I'd like to read just 100 lines in at a time or so.
2) Is there any easy way to determine the length of a text file (in lines) besides opening the file, reading each line and using a counter?
For future reference, file.readlines() returns a Python list object. So:
- f = open("fileName")
-
linesList = f.readlines()
-
f.close()
-
nLines = len(linesList)
-
nth = 5
-
nthLine = linesList[nth]