对文件进行监听、过滤

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)

 

相关文章:

  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-10-07
  • 2021-07-22
  • 2022-02-05
  • 2021-08-20
  • 2022-02-19
猜你喜欢
  • 2022-01-05
  • 2022-12-23
  • 2021-07-19
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案