PyYaml

作者: hellity | 来源:发表于2022-04-17 23:49 被阅读0次

    安装:

    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))
    

    相关文章

      网友评论

          本文标题:PyYaml

          本文链接:https://www.haomeiwen.com/subject/fwdxertx.html