Skip to content

Instantly share code, notes, and snippets.

@kewldan
Created September 12, 2023 19:41
Show Gist options
  • Save kewldan/da4ba38439fd5e5590d39d244b0471f0 to your computer and use it in GitHub Desktop.
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
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