import configparser import os import re def load_config(): config = configparser.ConfigParser( comment_prefixes=('#', ';'), # Define comment prefixes inline_comment_prefixes=('#', ';') # Enable inline comments ) config_path = os.path.join(os.path.dirname(__file__), 'config.ini') if not os.path.exists(config_path): exit("No config file") config.read(config_path) # Clean up any comment text that might have been included in values for section in config.sections(): for key in config[section]: # Get the original value value = config[section][key] # Remove inline comments if they exist # This regex looks for the first occurrence of a comment character that's not escaped comment_match = re.search(r'(?