Skip to content

Instantly share code, notes, and snippets.

@manuelep
Forked from giuserpe/conf.py
Last active June 27, 2017 21:15
Show Gist options
  • Save manuelep/198bb7baae473a786da2d62108406adf to your computer and use it in GitHub Desktop.
Save manuelep/198bb7baae473a786da2d62108406adf to your computer and use it in GitHub Desktop.
class conf:
def __init__(self, path):
self.config = configparser.SafeConfigParser()
self.config.read(path)
self.path = path
def write(self, section, option, value):
"""
http://www.programcreek.com/python/example/1033/ConfigParser.SafeConfigParser
Write the specified Section.Option to the config file specified by path.
Replace any previous value. If the path doesn't exist, create it.
Also add the option the the in-memory config.
"""
#~ config = configparser.SafeConfigParser()
#~ config.read(path)
if not self.config.has_section(section):
self.config.add_section(section)
self.config.set(section, option, value)
with open(self.path, 'w') as fp:
config.write(fp)
def read(self, section, option):
'''https://pymotw.com/2/ConfigParser/'''
#~ config = configparser.SafeConfigParser()
#~ config.read(path)
return self.config.get(section, option)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment