I have a text file and I need to read all the information that is located after the 25th line.
How to do it? Please, help!
I have a text file and I need to read all the information that is located after the 25th line.
How to do it? Please, help!
with open(file, 'r') as f: for i in range(25): f.readline() # в x будет 26 строка x = f.readline() If a small file, you can get a list of lines and drop the first 25:
lines = file.readlines()[25:] If the file is large, then in order not to read it all at once, you can use the fact that file is an iterator on strings separated by "\ n":
from itertools import islice lines = islice(file, 25, None) in this case, lines not a list, but an iterator that returns lines from a file during its crawl, starting from the 26th line, where file = open(filename) .
For example, you can do this:
with open("file.txt") as file: lines = file.readlines() lines = ''.join(lines[25:]) Something like this:
for linenum,line in enumerate(open('D:/file.txt','r+')): if linenum>24: print (line.strip()) if you count only, not output, then instead of the last line, x = line
+ in the mode do not need to add, if you do not write / read from the file simultaneously. 2- the code you start with 27 lines starts typing. - jfsSource: https://ru.stackoverflow.com/questions/601559/
All Articles