软件测试架构师的成长之路

使用yaml模块将信息写入配置文件

2018-07-17  本文已影响0人  远航天下
代码如下:
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()))
执行结果:
执行结果.png
写入的配置文件内容如下:
yaml配置文件.png
上一篇 下一篇

猜你喜欢

热点阅读