gpt4 book ai didi

python - 派克瓦化 : Validate data in a dictionary against a yaml file schema

转载 作者:太空宇宙 更新时间:2023-11-04 00:43:12 24 4
gpt4 key购买 nike

我有 python 字典和 schema.yaml。有没有办法验证两者?如果我将字典作为 data.yaml 转储到 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

所以我可以使用-

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com