【发布时间】:2018-09-11 14:49:54
【问题描述】:
当我向一个部分添加新选项并将文件写入配置时,它似乎总是复制该部分并使用新选项添加新选项。
理想情况下,我想避免这种情况,并且只有一个部分,我该如何实现?
示例出现
config.add_section("Install")
config.set("Install", "apt_installer", "True")
cfile = open("file.cfg", "w")
config.write(cfile)
cfile.close()
config.read("file.cfg")
config.set("Install", "deb_installer", "True")
cfile = open("file.cfg", "a")
config.write(cfile)
cfile.close()
当您打开 file.cfg 时,它会安装两次,一次使用 apt_installer,另一次使用 apt_installer 和 deb_installer。任何人都可以提供任何建议,我将不胜感激。
【问题讨论】:
标签: python python-3.x configparser