0

How to print every other line from a file?

I need to read from a file and print every other line but I have been unsuccessful. Any help would be appreciated!! thanks

20th May 2018, 9:45 PM
Aiyana
3 Réponses
+ 8
with open("filename.txt") as file: lines = file.readlines() for i in range(len(lines)): if not i % 2: print(lines[i]) Edit - here is an example https://code.sololearn.com/c9zfyKcPJ3uj/#py
21st May 2018, 1:39 AM
David Ashton
David Ashton - avatar
+ 2
Link your code and we should be able to tell you the answer.
20th May 2018, 11:31 PM
John Wells
John Wells - avatar
+ 1
Please consider more suitable keywords next time
20th May 2018, 11:47 PM
Øistein Hauge