如何在python中逐行寻找文件指针

时间:2016-04-27 13:35:54

标签: python

我试图逐行寻找文件指针,我找到了以下代码

fo = open("temp.tmp", "r")
print "Name of the file: ", fo.name
"""Assuming file has following 5 lines:

     This is 1st line
     This is 2nd line
     This is 3rd line
     This is 4th line
     This is 5th line
"""
line = fo.readline()
print "Read Line: %s" % (line)
# Again set the pointer to the beginning
fo.seek(3, 0)
line = fo.readline()
print "Read Line: %s" % (line)
fo.close()

但是,它逐个字符地移动文件指针,有没有办法逐行搜索指针

0 个答案:

没有答案