revelupex/config.py

21 lines
552 B
Python
Raw Normal View History

2024-08-10 19:47:47 +00:00
from configparser import ConfigParser
def load_config(filename='database.ini', section='postgresql'):
parser = ConfigParser()
parser.read(filename)
# get section, default to postgresql
config = {}
if parser.has_section(section):
params = parser.items(section)
for param in params:
config[param[0]] = param[1]
else:
raise Exception('Section {0} not found in the {1} file'.format(section, filename))
return config
if __name__ == '__main__':
config = load_config()
print(config)