yaml和json一样是一种数据呈现格式
-
对用户极为友好
-
跨语言,支持所有编程语言,如python、java、php、js等等
-
跨平台,如windows、linux、Mac
-
格式简单,比json更加简洁
-
应用极为广泛
1.读写文件
import yaml
def readYaml(path):
with open(path,'r',encoding='utf-8') as r:
config = yaml.full_load(r)
return config
def writeYaml(save_path,config):
with open(save_path,'w',encoding='utf-8') as w:
# yaml.safe_dump(config,w,default_flow_style=False, encoding='utf-8', allow_unicode=True)
yaml.dump(config,w,default_flow_style=False, encoding='utf-8', allow_unicode=True)
def changeYaml(yaml_path,obj):
config = readYaml(yaml_path)
config['common']['method'] = obj
writeYaml(yaml_path,config)
pass
if __name__ == '_