Is there a ConfigParser which keeps comments

Tim Chase python.list at
Wed Mar 14 19:13:12 CET 2012

On 03/14/12 12:06, Terry Reedy wrote:
> On 3/14/2012 6:07 AM, Gelonida N wrote:
>> Now I'm looking for a library, which behaves like config parser, but
>> with one minor difference.
>> The write() mehtod should keep existing comments.
> Assuming that you have not overlooked anything, I would just subclass
> ConfigParser with an altered write method.

It would require a lot more than that.  It would entail changing 
the reading as well so that it preserved the comments as well as 
the order of sections & keys, and a way of storing those 
associated comments in sequence.  I looked into it a fair while 
back and it was a LOT more work than I cared to do for minimal 
gain.  I wimped out and just documented it with "If you use the 
ability to (re)write a configuration file, it will not keep any 
comments or ordering from any original sources."


More information about the Python-list mailing list