Created
October 1, 2018 19:00
-
-
Save 3manuek/49cda5d4d2ec93ef91a279fc5a36e15b to your computer and use it in GitHub Desktop.
get connections from a config file
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
#!/usr/bin/python | |
from configparser import ConfigParser | |
def config(filename='endpoints.ini', section='postgresql'): | |
# create a parser | |
parser = ConfigParser() | |
# read config file | |
parser.read(filename) | |
# get section, default to postgresql | |
db = {} | |
if parser.has_section(section): | |
params = parser.items(section) | |
for param in params: | |
db[param[0]] = param[1] | |
else: | |
raise Exception('Section {0} not found in the {1} file'.format(section, filename)) | |
return db | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment