def tail(filename):#函数 f = open(filename,encoding='utf-8') while True: line = f.readline() if line.strip(): yield line.strip() g = tail('file')#引用 设置文件名为 file for i in g: #使用生成器监听 if 'python' in i: print('***',i)
对文件进行监听.过滤 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)
def tail(filename): f = open(filename,encoding='utf-8') while True: line = f.readline() if line.strip(): yield line.strip() g = tail('file')for i in g: if 'python' in i: print('***',i)
def tail(filename): f = open(filename,encoding='utf-8') while True: line = f.readline() if line.strip(): print(line.strip()) g = tail('file') def tail(filename): f = open(filename,encoding='utf-8') while True: line = f.readline() if line.strip(): if