num.yml文件数据内容
-
name: sunwukong
age: 20
sex: 男
-
name: zhubajie
age: 21
sex: 男
-
name: tieshan
age: 18
sex: 女
yaml中数组嵌套字典,通过角标定位数组,然后根据key值取对应的value参数信息
def test_yaml(self):
num=yaml.safe_load(open("./datas/num.yml",encoding='utf-8'))
print(num[2]['name'])
返回结果:
tieshan
datas1.yml文件数据内容
test: 123455
test1: 666666
获取yml文件中字典类型全部数据
def test_yaml1(self):
num = yaml.safe_load(open("./datas/datas1.yml", encoding='utf-8'))
print(num])
print(type(num))
返回结果:
{‘test’: 123455, ‘test1’: 666666}
<class ‘dict’>
字典类型,根据key获取对应的value值
def test_yaml1(self):
num = yaml.safe_load(open("./datas/datas1.yml", encoding='utf-8'))
print(num['test1'])
print(type(num))
返回结果:
666666
<class ‘dict’>