I love assert

Ben Finney ben+python at benfinney.id.au
Tue Nov 11 23:52:23 CET 2014


Terry Reedy <tjreedy at udel.edu> writes:

> We love 'assert' so much that we have 20-30 'assertXYZ' variations in
> unittest.

A function will not be disabled by a run-time option to the Python
interpreter.

> The statement 'assert expression' is almost equivalent to
>
> if not expression: raise AssertionError('expression')

With the important difference that this will be active no matter what
options Python's interpreter is run with. That makes it quite a
different proposition from using ‘assert’ statements.

-- 
 \     “You don't need a book of any description to help you have some |
  `\    kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)                                              scholar, 2011-05-08 |
Ben Finney




More information about the Python-list mailing list