时间:2022-05-05 10:20:17 | 栏目:Python代码 | 点击:次
# -*- coding: utf-8 -*-
# @Time : 2022/1/2 21:53
# @Author : lujunxian
# @File : test_yaml.py
import yaml
class TestYaml():
with open('./data.yaml','w',encoding='utf-8') as f:
request={
'test':{
'url':'test url',
'username':'test01'
},
'uat':{
'url':'uat url'
}
}
yaml.dump(request,f)
生成 data.yaml 如下
test: url: test url username: test01 uat: url: uat url
with open('./data.yaml','r',encoding='utf-8') as f:
print(yaml.safe_load(f))
结果如下
{'test': {'url': 'test url', 'username': 'test01'}, 'uat': {'url': 'uat url'}}