好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Pythonlinecache.getline()读取文件中特定一行的脚本

Python中使用标准库中的linecache中的getline方法可以从某个文件中读取出特定的一行。

比如:


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> import linecache
print linecache.getline( ' 2.1_open.py ' , 4 )


将返回我上一节事例代码文件2.1_open.py的第4行文字, 输出结果:
f = open('/home/evergreen/桌面/test')
查看linecache中的实现(我用的是Ulipad,所以直接将光标停留在linecache处,按F6键)

以上就是Python linecache.getline() 读取文件中特定一行的脚本的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于Pythonlinecache.getline()读取文件中特定一行的脚本的详细内容...

  阅读:31次