在python中更改配置文件而不删除commentS

时间:2018-07-13 15:24:44

标签: python configparser

我有一个简单的配置文件,如下所示,我写了一个引号来更新该文件。

 cat /tmp/cfg 
global key = value
section key = val
[section]
section key = val

[section2]
section key =10

我的代码工作正常,但删除了文件中的所有注释 例如,如果文件是

 cat /tmp/cfg2 
global key = value
section key = val
[section]
section key = val

[section2]
section key =10
#section key =20

以下代码是使用命令运行的

python  newmodconfig  --section all --config /tmp/cfg --key "section key" --value newval

我的尝试在下面 https://pastebin.com/tbL6iNb2

0 个答案:

没有答案
相关问题