python 文件监听
对文件进行监听、过滤
def tail(filename): f = open(file=filename, mode='r', encoding='utf-8') # 打开文件不能用with,因为监听 while 1: # 死循环 line = f.readline().strip() if line: yield line g = tail('test') for i in g: if 'python' in i: print('>>>%s' % i) else: print(i)