-
-
Save manuelep/198bb7baae473a786da2d62108406adf to your computer and use it in GitHub Desktop.
This file contains 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
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