Pykwalify:根据yaml文件模式验证字典中的数据

2024-06-01 08:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有python字典和架构.yaml. 有没有一种方法来验证这两种方法?如果我把字典作为数据.yaml,我可以使用下面的代码进行验证。 有没有办法用字典验证模式文件?在

from pykwalify.core import Core
c = Core(source_file="data.yaml", schema_files=["schema.yaml"])
c.validate(raise_exception=True)

Tags: 文件数据方法代码fromcoreimportyaml
1条回答
网友
1楼 · 发布于 2024-06-01 08:29:09

我自己也找到了答案。从pyKwalify类的源Core类接受source_data,如果没有指定source_file

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

所以我可以用做-

^{pr2}$

相关问题 更多 >