Home >Backend Development >Python Tutorial >Python linecache.getline() script to read a specific line in the file
In Python, you can use the getline method in linecache in the standard library to read a specific line from a file.
For example:
import linecache
print linecache.getline('2.1_open.py', 4)
## will return The 4th line of text in the example code file 2.1_open.py of my previous section, the output result:
f = open('/home/evergreen/Desktop/test')
View the implementation in linecache ( I am using Ulipad, so just put the cursor at linecache and press F6)
The above is the detailed content of Python linecache.getline() script to read a specific line in the file. For more information, please follow other related articles on the PHP Chinese website!