mardi 21 mai 2019

Catching exceptions in else

Is this a good pythonic way to test something for equality, and catch exceptions in else?

try:
    # Check for equality
    debug.assert_eq(data, None)
    debug.assert_eq(id, None)
    debug.assert_eq(time, None)
    debug.assert_eq(group, None)

except Exception:
    print("OK")

else:
    raise Exception('None found')

Aucun commentaire:

Enregistrer un commentaire