python读取文件指定行

import linecache

file=open('3_2.txt','r')

linecount=len(file.readlines())

linecache.getline('3_2.txt',linecount)

 

这样做的过程中发现一个问题,因为我的脚本是循环读取3_2.txt文件,当3_2.txt发生变化时,读到的内容不变化,看了一下linecache应该是缓存的问题,查资料后发现果然是这样,在用linecache之前清除一下缓存就好了linecache.clearcache()。

posted @ 2014-12-10 20:47  yyxayz  阅读(3847)  评论(0编辑  收藏  举报