I have a simple config file like below and i wrote a quote to update the file.
cat /tmp/cfg
global key = value
section key = val
[section]
section key = val
[section2]
section key =10
My code works fine , but removes any comments i have in the file example if file was
cat /tmp/cfg2
global key = value
section key = val
[section]
section key = val
[section2]
section key =10
#section key =20
The below code is run using command
python newmodconfig --section all --config /tmp/cfg --key "section key" --value newval
My attempt is below https://pastebin.com/tbL6iNb2