PYTHON怎么从一堆 txt文件里面(是文件里面的内容)查找一堆关键字,然...
发布网友
发布时间:2022-04-23 00:43
我来回答
共3个回答
热心网友
时间:2023-01-23 16:16
from glob import glob
lstKwds = "a/j7/9/大".split("/")
lstTxtFiles = glob(r"D:\test\*.txt")
for strTxtFile in lstTxtFiles:
with open(strTxtFile, "r") as txtWrapper:
strContent = txtWrapper.read()
[print(strTxtFile, "->", "strKwd") for strKwd in lstKwds if strKwd in strContent]
热心网友
时间:2023-01-23 17:34
伪代码:
for f in os.listdir(dir):
if '.txt' in f:
with open(f,...) as fr
content = fr.read()
if a in content or j7 in contetent...:
print(f)
热心网友
时间:2023-01-23 19:09
if a in content or j7 in contetent...: