Python linecache.getline() script to read a specific line in the file

巴扎黑
Release: 2017-05-21 11:12:42
Original
4219 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template