求文件的m至n行

#!/usr/bin/env python
def read_file(file_name,start,stop):
    start_line = 0
    try:
        with open(file_name) as f:
            for line in f:
                start_line += 1          #计数循环
                if start <= start_line <= stop:
                    yield line
    except IOError, e:
        raise e
reslut = read_file('/etc/passwd',2,10)
for lines in  reslut:
    print lines,
        
上一篇:【codevs】刷题记录→_→(推荐看!)


下一篇:vlookup函数基本使用--如何将两个Excel表中的数据匹配;excel表中vlookup函数使用方法将一表引到另一表