目录
1. 写入
1.1 直接写入,会清空历史的文件内容
def writer_yaml(yaml_path):
with open(yaml_path,encoding="utf-8",mode="w") as f:
yaml.safe_dump({"data":[{"ces1":'123'},{"ces2":2}]},stream=f,allow_unicode=True)
1.2 参数化写入,且使用追加的形式
data = {"data2":[{"ces3":'444'},{"ces4":222}]}
def writer2_yaml(yaml_path,data):
with open(yaml_path,encoding="utf-8",mode="a") as f:
yaml.safe_dump(data,stream=f,