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)
本文共 304 字,大约阅读时间需要 1 分钟。
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)
转载于:https://www.cnblogs.com/BlameKidd/p/9338722.html