如何读取yaml文件

文件命名:xx.yaml

  import yaml
  1、打开文件 open
  2、加载文件数据为字典对象/列表对象
  yaml.load(fs,loader=yaml.FullLoader)

import yaml

with open("file.yaml", encoding="utf-8") as fs:
    # data = yaml.load(fs, yaml.FullLoader)
    data = yaml.load(fs, yaml.SafeLoader)
    # print(data)
    for key, value in data.items():
        print(key)
        print(value)

yaml文件内容:
log:
  name: python
  level: INFO
  file_ok: False
  file_name: python_file.log

mysql:
  user: mysql
  passwd: 123456

info:
  - xiao
  -

你可能感兴趣的:(python自动化测试,python测试开发,python)