
本文共 2445 字,大约阅读时间需要 8 分钟。
������������
������������������������������������������������������������������������������������
pip install pyyaml
YAML ������
YAML ������
-
YAML������������������������������������������tab���������������������������������������������������������������������
-
���������������������������������
- ���������������������������������������
key: value
- ������������������������������
{}
������������������������������������������ - ������������������������������
-
������������������������������������������������ - ������������������
#
���������
key: subkey: subvalue
- item1- item2
# ������������������key: value
YAML ������
������������������������������������������������������������������������������������
HOST: { 'host':'http://v.juhe.cn',}PATH: { 'path':'/toutiao/index',}EXPECT: { 'expect':'success!',}HttpApi: { "retcode": 200, "msg": "\u67e5\u8be2\u6210\u529f", "retlist": [ { "id": 3, "method": 2, "path": "/api/test2", "data": "{\"user\":\"test\",\"psw\":\"123123\"}", "content_type": 1, "headers": "{\"Cache-Control\":\"no-cache\"}", "auth_type": 1, "desc": "\u6d4b\u8bd5\u63a5\u53e32", "create_time": "2021-03-30/07:08", "update_time": "2021-03-30/07:37", "module": { "id": 3, "desc": "login", "name": "\u767b\u5f55\u6a21\u5757" } ] }
������ YAML ������
��������� Python ��������������������� yaml
��������������������� YAML ���������������������������������
import yaml
- ������������ YAML ������������������������������������������������������������
- ���������������������������������
-
������������������������������������������������������������ YAML ������������������������������������������
-
���������������������������������������������������������������������������������������������������������������������������
def read_yml(path, key): with open(path, encoding='utf-8') as f: data_json = f.read() res = yaml.safe_load(data_json) return res[key]
req = read_yml('conf.yml', 'HOST')print(req)
������������
������������������������������������������ YAML ���������������������������������������������������������������������
������������������������
������������������������������������������������������ YAML ���������
������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
