I\'m using a for loop to read a file, but I only want to read specific lines, say line #26 and #30. Is there any built-in feature to achieve this?
Thanks
file = '/path/to/file_to_be_read.txt' with open(file) as f: print f.readlines()[26] print f.readlines()[30]
Using the with statement, this opens the file, prints lines 26 and 30, then closes the file. Simple!