使用python读取yaml文件:
yaml文件数据:data.yaml
login_data:url: 'http://www.baidu.com'case1:user1: ''password1: '12345'errorText: '请输入用户名'case2:user2: 'admin'password2: ''errorText: '请输入密码'case3:user3: 'admin'password3: '123456'errorText: '登录成功'
python读取yaml文件数据:
# coding = utf-8import yaml
#方式一:
with open('data.yaml', mode='r', encoding='utf-8') as f:msg = yaml.safe_load(f)print(msg)#方式二:
stream = open('data.yaml', mode='r', encoding='utf-8')
msg = yaml.safe_load(stream)
print(msg)
stream.close()
读取结果: