First, I am new to Python and did search for answers, but no luck. So far what I found only returns a one line like my code below. I tried other solutions like itertools.islice
but always only get a one line back.
I have a file called data.txt
containing lines of data:
This is line one
This is line two
This is line three
This is line four
This is line five
This is line six
This is line seven
...
I have the following code:
with open('data.txt', 'r') as f:
for x, line in enumerate(f):
if x == 3:
print(line)
In this case it only prints
"This is line four".
I do understand why but how do I take it from here and have it print the lines 4, 7, 10, 13, ...?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…