0

In jsonschema validation, I am looking to print all the Validationerror of several instances with several respective schemas in one single for loop as opposed to one for loop for one round of validation. I want to do something like this:

validator = jsonschema.Draft4Validator(schema1)
errors1 = validator.iter_errors(instance1)
validator = jsonschema.Draft4Validator(schema2)
errors2 = validator.iter_errors(instance2)
for error in errors1 + errors2:
    print error.message

But, I can't do errors1 + errors2 as they are of type generator. Is there a way to add all the errors into one single iterable so I can use just one for loop? Any help appreciated. Thanks.

Arteezy
  • 193
  • 2
  • 12

1 Answers1

0

Similar question is here How to join two generators in Python?

You have to use itertools.chain() function to join generators

for error in itertools.chain(errors1, errors2):
    print error.message
Arteezy
  • 193
  • 2
  • 12