How can I parse a YAML file in Python

后端 未结 8 1194
醉话见心
醉话见心 2020-11-22 14:54

How can I parse a YAML file in Python?

8条回答
  •  忘了有多久
    2020-11-22 15:12

    First install pyyaml using pip3.

    Then import yaml module and load the file into a dictionary called 'my_dict':

    import yaml
    with open('filename.yaml') as f:
        my_dict = yaml.safe_load(f)
    

    That's all you need. Now the entire yaml file is in 'my_dict' dictionary.

提交回复
热议问题