How can I parse a YAML file in Python

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

How can I parse a YAML file in Python?

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

    To access any element of a list in a YAML file like this:

    global:
      registry:
        url: dtr-:5000/
        repoPath:
      dbConnectionString: jdbc:oracle:thin:@x.x.x.x:1521:abcd
    

    You can use following python script:

    import yaml
    
    with open("/some/path/to/yaml.file", 'r') as f:
        valuesYaml = yaml.load(f, Loader=yaml.FullLoader)
    
    print(valuesYaml['global']['dbConnectionString'])
    

提交回复
热议问题