Skip to content

Instantly share code, notes, and snippets.

@giuserpe
Last active June 27, 2017 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giuserpe/1da7b5afcbcb229b7387a1898c7e38ef to your computer and use it in GitHub Desktop.
Save giuserpe/1da7b5afcbcb229b7387a1898c7e38ef to your computer and use it in GitHub Desktop.
class conf:
def __init__(self):
config = configparser.SafeConfigParser()
config.read(path)
#~ pass
def w(self, path, 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 config.has_section(section):
config.add_section(section)
config.set(section, option, value)
fp = open(path, 'w')
config.write(fp)
fp.close()
def r(self, path, section, option):
'''https://pymotw.com/2/ConfigParser/'''
#~ config = configparser.SafeConfigParser()
#~ config.read(path)
return config.get(section, option)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment