json文件的层级不确定,key参数用“.”隔开,把value内容添加到key指定的位置,可以更新config(dict)对象
def update_config(config, key, value):
"""
update config
:param config:
:param key:
:param value:
:return:
"""
ks = key.split(".")
value = value.strip()
temp=config
for index,key in enumerate(ks):
if(key not in temp):
temp[key]={}
if index<len(ks)-1:
temp=temp[key]
if isinstance(temp[key],list):
temp[key].append(value)
else:
temp[key]=value
网友评论