Python Uncategorized

Change a value with configparser for python

configparser is a great module to store configuration information into a file
a config file could look like this:

value = 7

To load the value from the file

import configparser

config = configparser.ConfigParser()'config.ini')
value = self.config['DEFAULT']['value']
# output value 7

To change the value in the file:

# set new value
config.set('DEFAULT', 'value', '42')

# save the file
with open(self.config_filename, 'w') as configfile: