凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

重载configparser配置文件

cf2
2020-02-23 python 1079
from configparser import ConfigParser

# 重载 configparser配置文件
def reload_conf(cf1_file,cf2_file):
    cf = ConfigParser()
    cf.read(cf1_file)
    cf2 = ConfigParser()
    cf2.read(cf2_file)
    for group in cf.sections():
        cf2.add_section(group)
        for key in cf.options(group):
            cf2.set(group,key,cf.get(group,key))

    with open(cf2_file,"w",encoding="utf-8") as f:
        cf2.write(f)
'''
demo:
cf1_file = "./config/d.ini"
cf2_file = "./config/t.ini"
reload_conf(cf1_file,cf2_file)
'''


文章评论

0条评论