我有 python 字典和 schema.yaml。有没有办法验证两者?如果我将字典转储到 yaml 文件中作为 data.yaml,我可以使用下面的代码进行验证。 有没有办法用字典验证模式文件?
from pykwalify.core import Core
c = Core(source_file="data.yaml", schema_files=["schema.yaml"])
c.validate(raise_exception=True)
最佳答案
我自己找到了答案。如果未指定 source_file
,则从 pyKwalify 类的源 Core
类接受 source_data
。
class Core(object):
""" Core class of pyKwalify """
def __init__(self, source_file=None, schema_files=[], source_data=None, schema_data=None, extensions=[]):
...
...
if self.source is None:
log.debug(u"No source file loaded, trying source data variable")
self.source = source_data
所以我可以使用 as-
c = Core(source_data=data_dict, schema_files=["schema.yaml"])
关于python - 皮克瓦利 : Validate data in a dictionary against a yaml file schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40926862/