This try/except could be part of the function, including the print. that way we can turn it into if not verComp.blah.foo(): cfg.save() sys.exit(1)