[Tony Meyer] > Allowing 'surgical' editing of configuration files, as has been > proposed many times both here and c.l.p would not require > ConfigParser to be entirely rewritten (just more extensive > modification of the write() method).
After writing the summary of this thread, I figured I might as well prove this by submitting a patch, so did so: [ 1410680 ] Add 'surgical editing' to ConfigParser <http://python.org/sf/1410680> So there are now at least three open ConfigParser patches, all addressing similar things, although not in the same way, and all three could actually be applied. My patch (which includes new unittests and a marked-up doc patch) runs through a file and updates it to match the in-memory configuration object. Comments, blank lines, and order are preserved. By default (this can be turned off with a keyword arg) new sections/options are added to the file as well (new options in existing sections are added at the end of the last instance of that section, new sections are added at the end of the file). These new options are added in alphabetical (well, list.sort()) order, so ordering is consistent, and if an empty file is 'updated' one ends up with the output of write() but sorted. This is essentially a tidied-up version of the SpamBayes code I wrote a few years back. If anyone is still interested in adding this, feel free to take a look at the tracker :) =Tony.Meyer _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com