If you ever find that you need to read the same line from a file every time you read it, Python makes this task a three-line program. First, import the linecache module:
import linecache
The linecache module allows you to access any line from any file. Of its three methods, the one you are likely to use the most is getline. The syntax for getline is as follows:
linecache.getline('filename', line_number)
If you have a file called 'myfile.txt' and would like to read line 138 from it, getline allows you to do so with ease.
retrieved_line = linecache.getline('myfile.txt', 138)
Then you can simply print retrieved_line or otherwise manipulate the data of line 138 without doing surgery on the file itself.
If you would like to read more about the linecache module, visit the Python documentation .

