一、参考链接
https://pyyaml.org/wiki/PyYAMLDocumentation http://www.ruanyifeng.com/blog/2016/07/yaml.html
二、python类型转换为yaml
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
三、yaml转换为python类型
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'}}
|