0
how do I create a program that only read line3,5,7,9 etc.
3 Answers
+ 2
if you want to only read line number 3 from a file :
Import linecache
line = linecache.getline(thefilename, 3)
Otherwise:
Import linecache
n=3
for n in range (10)
line = linecache.getline(thefilename, n)
n+=2
0
Does the function 'file.readlines()' can be used as well?
0
i= 1
for line in open(file.txt, "r"):
If i %2 != 0:
print (line)
i+=1