重载configparser配置文件
2020-02-23 python 1505
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)
相关文章
文章评论
-
-
-
0条评论