需求:根据用户的需求,查找一个文件用户输入的内容并把它打印出来 def find(file,aim): with open(file,encoding='utf-8') as g: for i in g: if aim in i: yield i l = find('log','姐姐') for i in l: print(i.strip()) View Code 通过定义了一个生成器,在调用是传入传输,就可以实现这个需求。 来源:https://www.cnblogs.com/zly9527/p/11392074.html 标签 用户需求