【发布时间】:2018-01-30 10:19:42
【问题描述】:
我有一本包含配置信息的字典:
my_conf = {
'version': 1,
'info': {
'conf_one': 2.5,
'conf_two': 'foo',
'conf_three': False,
'optional_conf': 'bar'
}
}
我想检查字典是否符合我需要的结构。
我正在寻找这样的东西:
conf_structure = {
'version': int,
'info': {
'conf_one': float,
'conf_two': str,
'conf_three': bool
}
}
is_ok = check_structure(conf_structure, my_conf)
是否有任何解决方案或任何库可以使实现check_structure 更容易?
【问题讨论】:
-
看起来这个包完全符合你的需要:github.com/andrey-ushakov/dict-schema-validator
标签: python validation dictionary schema config