read big file

import linecache

def eachlineof(filename):
with open(filename, 'r') as f:
for cnt, line in enumerate(f):
a = str(cnt) + ',' + line.strip('\n')
yield a

for i in eachlineof('t.txt'):
if 'you' in i:
num = i.split(',')[0]
linecache.clearcache()
print linecache.getline('t.txt',int(num)+1).strip('\n')

posted @ 2017-02-21 23:44  idlewith  阅读(117)  评论(0)    收藏  举报