一个文件夹下所有文件只要含有特定内容,就显示文件

def func(filename, aim):
    with open(filename) as f:
        for i in f:
            if aim in i:
                yield i


g = func('D:\Temp\minitor.txt', 'hello')
for i in g: # 这个g就是func,要求要读完。
    print(i.strip())
原文地址:https://www.cnblogs.com/shuoran/p/11653219.html