0

I am evaluating Great Expectations to do some Data Cleaning.

I have managed to get most of code working for our needs. I am having a problem with the Attribute needed to code for unsuccessful results. For example, the following code will print "Successful" if the 'validation_results' are success

if validation_results["success"]:
    print ("Successful")

But I don't know what attribute to use for failed results.

I have tried the following:

if validation_results["failure"]:
    print ("Failed")

if validation_results["unsuccessful"]:
    print ("Failed")

if validation_results["false"]:
    print ("Failed")

But I get the error message: object has no attribute for each of the failure attempts above.

Does anyone know what attribute will give me a failure output?

Patterson
  • 1,927
  • 1
  • 19
  • 56

1 Answers1

0

I think you want to check whether a key is exists in the dictionary or not. When you call a key that didn't exists, it will return an error. But you can check is the key is in the dict using this approach.

if "success" in validation_results:
    print ("Successful")

if "failure" in validation_results:
    print ("Failed")

if "unsuccessful" in validation_results:
    print ("Failed")

if "false" in validation_results:
    print ("Failed")

This is not best practice. It will be better to create a "status" key in the dict that contain success, failure, unsuccessful, or false

Rizquuula
  • 578
  • 5
  • 15
  • Riz, I understand what you're saying but there is an inbuilt attribute that can be used, but I don't know what it is – Patterson Nov 16 '21 at 11:09