一天一更小技巧之python-yaml 使用:
yaml 是一个很好的配置文件,可以存储任何形式的文件。
首先配置yaml文件
填写自己想要保存的数据
python 代码使用yaml
#读取
path = r'输入yaml路径'
with open(path, "r", encoding='utf-8') as f:
data = yaml.load_all(f, loader=yaml.FullLoader)
#遍历yaml文件
for prolist in data:
result = prolist
res = result["xxx"]
#写入
with open(path, "w", enconding='utf-8') as f:
yaml.dump({"xxxx": xxx, "xxxx": xxx}, f)