Ok i am planning on using the configparser module for creation of a few ini configuration files, I have ran into some trouble though.
How can i write certain sections of my config to different ini files?
I have read all through the official docs on it, and don’t seem to see anything that allows this to be done.
Any suggestions?
You could define a subclass of one of the
ConfigParserclasses and override itswritemethod. For example:I can test my subclass with something like this:
After I run this code, the file
section1.inicontains:and
sections2and3.inicontains:And best of all, the
ConfigParser.read(...)method already accepts multiple filenames, so I can re-read both configuration files with:Edit: I missed that the original question was asking about Python 3, so here’s the above code converted to Python 3:
And the test code converted to Python 3: