2016-12-02 5 views
2

私はpython辞書とschema.yamlを持っています。両方を検証する方法はありますか?辞書をyamlファイルにdata.yamlとしてダンプすると、以下のコードを検証用に使用できます。 辞書でスキーマファイルを検証する方法はありますか?Pykwalify:辞書のデータをyamlファイルのスキーマに対して検証する

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

答えて

2

私は自分自身で答えを見つけました。 pyKwalifyクラスのソースのCoreクラスでは、が指定されていない場合はsource_dataを受け入れます。だから私は

c = Core(source_data=data_dict, schema_files=["schema.yaml"]) 
+1

AS-使用することができますあなたが 'あなたの最後のコード行でもしかして

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 

ではなくsource_file''のsource_data'? – dougli1sqrd

+0

右@ dougli1sqrd。修正されました。ありがとう。 – Rilwan

関連する問題