import os,sys,re
# 打开文件
key = input(‘Enter the key word:\n‘)
path = "C:\\Users\\Administrator\\Python35-32\\test"#替换为自己的文件路径
for f in os.listdir(path):
if f.endswith(‘.txt‘):
for file in open(f):
if key in file:
print(file)
python编程快速上手之第8章实践项目参考答案(8.9.3)
原文:http://www.cnblogs.com/flying-wyf/p/6702087.html