0

how do I create a program that only read line3,5,7,9 etc.

24th Sep 2016, 2:22 AM
Leo Chen
Leo Chen - avatar
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
24th Sep 2016, 5:32 AM
Md Mizanur Rahman
Md Mizanur Rahman - avatar
0
Does the function 'file.readlines()' can be used as well?
29th Sep 2016, 11:12 AM
Caio Conde
Caio Conde - avatar
0
i= 1 for line in open(file.txt, "r"): If i %2 != 0: print (line) i+=1
21st Oct 2016, 6:09 PM
Dmitrii Sky
Dmitrii Sky - avatar