1 def tail(filename): 2 f = open(filename, encoding='utf-8') 3 while 1: 4 line = f.readline() 5 if line.strip(): 6 yield line.strip() 7 g = tail('file') 8 for i in g: 9 if 'python' in i: 10 print('***',i)