Created
September 12, 2023 19:41
-
-
Save kewldan/da4ba38439fd5e5590d39d244b0471f0 to your computer and use it in GitHub Desktop.
Config parser (loader), if config doesn't exists it will copy default_config.ini and require a restart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import logging | |
import os | |
import shutil | |
config = {} | |
if not os.path.exists('config.ini'): | |
shutil.copyfile('default_config.ini', 'config.ini') # Copy defaults to config.ini | |
logging.warning(f"Config was created. Restart the program") | |
exit(0) | |
else: | |
ini = configparser.ConfigParser() | |
ini.read('config.ini', encoding='utf-8') | |
for section in ini: | |
if section != 'DEFAULT': | |
config[section] = dict(ini[section]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment