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)

 

posted @ 2019-05-12 17:37  市丸银  阅读(295)  评论(0编辑  收藏  举报