Lasse Nørfeldt <la...@norfeldt.com> added the comment: When running a script like this
``` import os import utils.logger import utils.stats import utils.dir import utils.convert import re import CONSTANTS HTML_DIR_PATH = CONSTANTS.RAW_DATA_DIR + '/html' folder_contents = [fc for fc in os.listdir( HTML_DIR_PATH) if '.html' in fc and 'tablet' in fc and (', ' in fc or ' og ' in fc)] utils.dir.remove_dir(CONSTANTS.PROCESS_DATA_DIR) md_output_path = f'{CONSTANTS.PROCESS_DATA_DIR}/md' utils.dir.create_dir(md_output_path) convert_logger = utils.logger.LogFile('convert') for index, filename in enumerate(folder_contents): html_text = open(f'{HTML_DIR_PATH}/{filename}', 'r', encoding='utf-8').read() md_text = utils.convert.word_html_to_markdown(html_text) with open(f'{md_output_path}/{filename}.md', 'w+') as md_file: md_file.write(md_text) if any([flag in md_text for flag in CONSTANTS.INSPECT_FLAGS]): convert_logger.entry('Flag detected!') else: convert_logger.entry('Success! - no flags detected') procent = int(100*(index+1)/len(folder_contents)) print(f"{index+1}/{len(folder_contents)} ({procent}%)", end='\r') if index > 50: break utils.stats.gen_frequency_stats(convert_logger.path) utils.stats.gen_frequency_stats(utils.logger.EXCIPIENTS.path) utils.stats.gen_alpha_sort_stats(utils.logger.EXCIPIENTS.path) os.system(f'cat {utils.logger.EXCIPIENTS.path}.freq.stats') ``` I get an error like this ``` Traceback (most recent call last): File "dev/run_convert.py", line 40, in <module> utils.stats.gen_frequency_stats(utils.logger.EXCIPIENTS.path) File "~/scraper-produktresume.dk/utils/stats.py", line 5, in gen_frequency_stats lines = _gen_list_from_lines(path_to_log_file) File "~/scraper-produktresume.dk/utils/stats.py", line 24, in _gen_list_from_lines with open(path_to_log_file, 'r') as log_file: FileNotFoundError: [Errno 2] No such file or directory: 'PROCESSED/excipients.log' ``` Was not expecting that since my utils.logger.py looks like this ``` import os import logging import CONSTANTS class LogFile: def __init__(self, logger_name): if not os.path.exists(CONSTANTS.PROCESS_DATA_DIR): os.makedirs(CONSTANTS.PROCESS_DATA_DIR) self.path = f'{CONSTANTS.PROCESS_DATA_DIR}/{logger_name}.log' self.file_handler = logging.FileHandler(self.path) self.logger = logging.getLogger(f'{logger_name}') self.logger.setLevel(logging.INFO) self.logger.addHandler(self.file_handler) def entry(self, text): self.logger.info(text) EXCIPIENTS = LogFile('excipients') ``` I'm both creating the file via the lib `os` (just to be sure that was not the case) and in the `self.file_handler` ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41499> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com