I love assert

Richard Riehle rriehle at itu.edu
Fri Nov 14 23:09:04 CET 2014

On Tuesday, November 11, 2014 11:41:06 AM UTC-8, Peter Cacioppi wrote:
> I get the impression that most Pythonistas aren't as habituated with assert statements as I am. Is that just a misimpression on my part? If not, is there a good reason to assert less with Python than other languages?
> As far as I can tell, Python supports assert perfectly well. When run with the optimization flagging, the asserts are truly removed.
> I think one needs to take care with some basic assert coding - it's not a substitute for unit tests, it doesn't absolve you of normal exception responsibilities, and, most of all, it should be used for passive inspection and not action. But given these guidelines, I still find it very useful as "active comments".
Reply & Comment:

I am new to this group, but really like Python.   One of the things I find helpful is to combine the assert with the decorator capability to produce code that is close to, although not identical to, the Design by Contract features built-in to Eiffel and Ada (2012).  I find that not a lot of Python user really appreciate the power of decorators.   

Richard Riehle, PhD, International Technological University, San Jose, CA.

More information about the Python-list mailing list