标签:
#!/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
finally:
f.close()
reslut = read_file(‘/etc/passwd‘,2,10)
for lines in reslut:
print lines,
标签:
原文地址:http://www.cnblogs.com/huangweimin/p/5668521.html