If you know the exact line number, you can use the python module to read a specific line. You do not need to open the file. linecache
import linecache
line = linecache.getline("test.txt", 3)
print(line)
Conclusion:
chart
If you want to start reading from this line, you can use . islice
from itertools import islice
with open('test.txt','r') as f:
for line in islice(f, 3, None):
print(line)
Conclusion:
chart
dang!
It
Works
If you do not know the exact line number and want to start after the line containing this particular line, use another for the loop.
with open('test.txt','r') as f:
for line in f:
if "chart" in line:
for line in f:
print(line)
Conclusion:
dang!
It
Works
test.txt
contains:
hello
world!
chart
dang!
It
Works
, . , , , . .