I'm trying to write a function that tries to read a config and if fails, creates a new one and writes to the file "settings.ini". This feels really chunky and not particularly concise. Is this the supposed way of reading a configparser file?
from configparser import ConfigParser
def getSettings(self):
try:
with open('settings.ini') as f:
return config.read_file(f)
except:
config['DEFAULT'] = {'Host': '127.0.0.1',
'Port': '5822'}
return config['DEFAULT']
config
\$\endgroup\$