yaml + easydict 写 配置文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38131594/article/details/83895596

yaml

test.yaml文件:

name: Tom Smith
age: 37
spouse:
    name: Jane Smith
    age: 25
children:
 - name: Jimmy Smith
   age: 15
 - name1: Jenny Smith
   age1: 12

python文件:

import yaml,os
 
#获取文件全路径
filename = os.path.join(os.path.dirname(__file__),'test.yaml').replace("\\","/")
 
f = open(filename)
y = yaml.load(f)
 
print s

输出:

{'age': 37, 'spouse': {'age': 25, 'name': 'Jane Smith'}, 'name': 'Tom Smith', 'children': [{'age': 15, 'name': 'Jimmy Smith'}, {'age1': 12, 'name1': 'Jenny Smith'}]}

easydict

easydict的作用:可以使得以属性的方式去访问字典的值

>>> from easydict import EasyDict as edict
>>> d = edict({'foo':3, 'bar':{'x':1, 'y':2}})
>>> d.foo
3
>>> d.bar.x
1

>>> d = edict(foo=3)
>>> d.foo
3

yaml+ easydict -> CNN config

参考OICR代码here

References

[1]Python读取Yaml文件
[2]python 中easydict的简单使用

猜你喜欢

转载自blog.csdn.net/qq_38131594/article/details/83895596