yaml
test.yaml文件:
name: Tom Smith
age: 37
spouse:name: Jane Smithage: 25
children:- name: Jimmy Smithage: 15- name1: Jenny Smithage1: 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的简单使用