python对不同类型文件(doc,txt,pdf)的字符查找
python对不同类型文件的字符查找 TXT文件: def txt_handler(self, f_name, find_str): """ 处理txt文件 :param file_name: :return: """ line_count = 1; file_str_dict = {} if os.path.exists(f_name): f = open(f_name, 'r', encoding='utf-8') for line in f : if find_str in line: file_str_dict['file_name'] = f_name file_str_dict['line_count'] = line_count break else: line_count += 1 return file_str_dict docx文件 需要用到docx包 pip install python-docx 参考https://python-docx.readthedocs.io/en/latest/ from docx import Document def docx_handler(self, f_name, find_str): """ 处理word docx文件 :param file_name: :return: """ # line_count = 1;