我有喜欢100+文件在目录中,我需要找出哪些文件包含的话,我在泰国寻找
谢谢你
我试过了,但没有用
import pandas as pd
import re
import os
FOLDER_PATH = r'C:\Users\project'
list = os.listdir(FOLDER_PATH)
def is_name_in_csv(word,csv_file):
with open(csv_file,"r") as f:
data = f.read()
return bool(re.search(word, data))
word = "บัญชีรายรับ"
for csv_file in list:
if is_name_in_csv(word,csv_file):
print(f"find the {word} in {csv_file}")
`
1条答案
按热度按时间cbjzeqam1#
你不需要regex,你可以简单地检查
word in fileContents
是否是list
。另外,我把list
改成了paths
,因为list
是一个内置的python关键字。