Lets say you have a python file with 50 lines of code in it, and you want to read a specific range lines into a list. If you want to read ALL the lines in the file, you can just
If there are lots and lots of lines in your file, I believe you should consider using f.readline()
(without an s
) 27 times, and only save your lines starting wherever you want. :)
Else, the other ones solution is what I would have done too (meaning : f.readlines()[23:28]
. 28, because as far as I remember, outer range is excluded.