One thing you could do is to create your own version of assert:
def confirm(expression):
if not expression:
raise AssertionError
Then, instead of using assert whatever()
, you could instead do confirm(whatever())
.
Alternatively, if you want to emulate perl, you could do the following:
def die():
raise Exception()
whatever() or die()
If whatever()
returns True
, die()
will never execute (due to boolean short-circuiting), and the program will merrily chug away. If whatever()
returns False
, then the program will terminate.
Technically, this is two more characters then perl, but you could rename die
to d
, and end up writing the same amount of characters.
I'm pretty sure that this isn't a Pythonic way of doing things, but the option is available, if you prefer it that way.