Python configurator: copying comments from input file

I use configparser and Python 3.3 to create a script that makes some small changes to the configuration files. These configuration files often contain comment lines, for example:

[Section]
Value1=Foo
;Very important comment
;Another very important comment
Value2=Bar

It is understood that Python deletes them when it writes a new version of the configuration file, but something like a problem. Is there a way to copy comments into a new configuration file? (Unfortunately, order is also important. Thanks to OrderedDict, the order of configuration settings is maintained properly, but the order of comments should also be supported, which I hope will not be a problem.)

Thanks!

+4
source share
1 answer

/ : REM_x= , ( ):

[Section]
Value1=Foo
REM_1=Very important comment
REM_2=Another very important comment
REM_Value2=Bar
Value2=Baz
0

All Articles