当前位置: 移动技术网 > IT编程>脚本编程>Python > python读取yaml配置文件

python读取yaml配置文件

2020年07月07日  | 移动技术网IT编程  | 我要评论
安装yamlpip 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 datayaml数据类型list: -

安装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"
    }
}

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

本文地址:https://blog.csdn.net/weixin_42132508/article/details/107162171

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网