安装:
pip install PyYaml
读取 yaml 文件
import yaml
with open('config.yaml','r',encoding='utf-8') as f :
print(yaml.safe_load(f))
对文件进行某项修改:
ss = yaml.safe_load(f)
ss['allow-lan'] = 'true'
对修改后的文件进行存储:
with open('config.yaml','w',encoding='utf-8') as f :
yaml.dump(ss,f)
with open("file_to_edit.yaml", 'w') as f:
f.write(yaml.safe_dump(ss))
网友评论