0
我希望能够使用模块jsonschema的iter_errors
功能。我导入了模块jsonschema,但无法访问iter_errors。为什么我无法导入模块?
我怀疑这可能是因为该模块需要更新,如果是这种情况,我该如何做?
我试着重新安装它,python提示我使用命令'升级',我不确定如何使用。
Requirement already satisfied (use --upgrade to upgrade): jsonschema in /Library/Python/2.7/site-packages
Cl
谢谢!
RE评论:
我下面的代码使用here,从验证器类调用该函数:
EX CODE:
>>> schema = {
... "type" : "array",
... "items" : {"enum" : [1, 2, 3]},
... "maxItems" : 2,
... }
>>> v = Draft3Validator(schema)
>>> for error in sorted(v.iter_errors([2, 3, 4]), key=str):
... print(error.message)
4 is not one of [1, 2, 3]
[2, 3, 4] is too long
我的代码: 其中x是样本JSON
with open('gc_schema_test.json', 'r') as handle:
schema = json.load(handle)
v = Draft3Validator(schema)
for error in sorted(v.iter_errors(x), key=str):
print(error.message)
你试图用来访问'iter_errors'的实际代码是什么? 'import'只是将模块名称导入到您的名称空间中;你最需要'jsonschema.iter_errors'。 – geoffspear
这是否回答你的问题? – goldisfine