python读取yaml配置文件

安装yaml

pip install PyYAML

 

读取

def read_yaml():
    path = 'yaml_ini_data.yaml'
    # print(path)
    file = open(path, 'rb')
    result = file.read()
    data = yaml.load(result, Loader=yaml.FullLoader)
    file.close()
    return data

 

yaml数据类型

list:
  - 'list_1'
  - 'list_2'
  - 'list_3'
  - 'list_4'
  - 'list_5'
  - 'list_6'

 

dict: 'dict'

 

复杂字典:
dict_data :
  'address': 'test'
  'raw' : 'test'
  'coinCode': 'test'
  'amount': 1000
  'betSite':
    '21' : 1000

 

等同于json:
{
    "address": "test",
    "raw": "test",
    "coinCode": "test",
    "amount": 1000,
    "betSite": {
        "test": "1000"
    }
}

 

暂时只用到这几种,其他以后用到再写

posted @ 2020-07-07 19:07  Echo丶Mikasa  阅读(201)  评论(0)    收藏  举报