If you look at the code defining the RawConfigParser.write
method inside ConfigParser.py
you'll see that the equal signs are hard-coded. So to change the behavior you could subclass the ConfigParser you wish to use:
import ConfigParser
class MyConfigParser(ConfigParser.ConfigParser):
def write(self, fp):
"""Write an .ini-format representation of the configuration state."""
if self._defaults:
fp.write("[%s]\n" % DEFAULTSECT)
for (key, value) in self._defaults.items():
fp.write("%s : %s\n" % (key, str(value).replace('\n', '\n\t')))
fp.write("\n")
for section in self._sections:
fp.write("[%s]\n" % section)
for (key, value) in self._sections[section].items():
if key != "__name__":
fp.write("%s : %s\n" %
(key, str(value).replace('\n', '\n\t')))
fp.write("\n")
filename='/tmp/testconfig'
with open(filename,'w') as f:
parser=MyConfigParser()
parser.add_section('test')
parser.set('test','option','Spam spam spam!')
parser.set('test','more options',"Really? I can't believe it's not butter!")
parser.write(f)
yields:
[test]
more options : Really? I can't believe it's not butter!
option : Spam spam spam!