代码如下:
author = 'damao'
import os
import yaml
"""将数据写入配置yaml文件"""
platform_address = {"test_cscnew": "111111111111111111111",
"beta_cscnew": "222222222222222222222",
"test_ppcnew": "333333333333333333333",
"beta_ppcnew": "444444444444444444444"}
test_csc_list = ["aaa","bbb","ccc"] #
test_ppc_list = ["aaa","bbb","ccc"]
beta_csc_list = ["aaa","bbb","ccc"]
beta_ppc_list = ["aaa","bbb","ccc"]
path = os.path.dirname(os.path.realpath(__file__))
testpath = os.path.join(path, "test.ymal")
# 写入yaml文件
with open(testpath, 'w', encoding="utf-8")as f:
yaml.dump([platform_address,test_csc_list,beta_csc_list,beta_ppc_list,test_ppc_list],f,)
# 读取test.ymal文件
a = open(testpath,'r')
print(yaml.load(a.read()))
执行结果:
写入的配置文件内容如下: