python接口自动化测试二十九:yaml配置文件的写和读
2021-06-30 14:07
标签:python int 安装 print st3 host os.path loader 接口自动化测试 写入配置文件: # 将字典写入到yaml curpath = os.path.dirname(os.path.realpath(__file__)) # 写入到yaml文件 a = yaml.load(open(yamlpath, "r").read(), Loader=yaml.Loader) python接口自动化测试二十九:yaml配置文件的写和读 标签:python int 安装 print st3 host os.path loader 接口自动化测试 原文地址:https://www.cnblogs.com/zhongyehai/p/9642008.html# 先安装ruamel.yaml模块
import os
# 先安装ruamel.yaml模块
from ruamel import yaml
dict = {
‘host1‘: ‘123‘,
‘host2‘: ‘456‘,
‘host3‘: ‘789‘,
‘host4‘: ‘147‘,
‘host5‘: {‘asd‘: ‘123‘}
}
yamlpath = os.path.join(curpath, "config.yaml")
with open(yamlpath, "w", encoding="utf-8") as f:
yaml.dump(dict, f, Dumper=yaml.RoundTripDumper)
读取配置文件# 读取yaml文件
# a = open(yamlpath, "r")
# print(yaml.load(a.read(), Loader=yaml.Loader))
print(a)
print(a[‘host1‘])
文章标题:python接口自动化测试二十九:yaml配置文件的写和读
文章链接:http://soscw.com/index.php/essay/99884.html