Changing a value in an ini file using ConfigParser Python

So, I have this settings.ini:

[SETTINGS] value = 1 

And this python script

 from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') print parser.get('SETTINGS', 'value') 

As you can see, I want to read, and then replace the value "1" with another. All I could do was read. I searched on the net how to replace it, but I did not find it.

+4
source share
1 answer

As from the sample documentation:

https://docs.python.org/2/library/configparser.html

 parser.set('SETTINGS', 'value', '15') # Writing our configuration file to 'example.ini' with open('example.ini', 'wb') as configfile: parser.write(configfile) 
+14
source

All Articles