[英]Python - replace part of the string inside of all files within given directory with previously splitted string
[英]search a given string splitted by comma in pdf using python
例如,如果我有這樣的輸入 ['thermostat', 'lamp', 'motor'] 我必須搜索如下
同樣,我必須做 n 長度。 請幫助我實現這些比較組合。
如果我知道字符串的確切長度,我已經搜索了單個輸入和多個輸入,如下所示:
file_path=myfilepath
file_type = "pdf"
search_string = input("Enter Search String:").split(",")
seen = []
j = 1
for filename in os.listdir(file_path):
if(filename.endswith(file_type)):
text = parser.from_file(file_path + '\\' +filename)
identified_text = text['content']
# print(len(search_string))
# print(lambda x : all(search_string[x] for s in search_string))
if len(search_string) == 1:
if re.search(search_string[0], identified_text, re.IGNORECASE):
if filename not in seen:
print(filename)
if len(search_string) > 1:
if re.search(search_string[0], identified_text, re.IGNORECASE) and re.search(search_string[1], identified_text, re.IGNORECASE):
if filename not in seen:
print(filename)
我必須評估提取的文件中的字符串輸入以及是否應該動態生成條件
按照本教程閱讀pdf並獲取列表中的數據: https://pythontips.com/2016/02/25/ocr-on-pdf-files-using-python/
然后使用 list.split(',') 拆分列表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.