Anything equivalent to cassert in C++?

Simon Forman sajmikins at
Tue Nov 17 23:01:38 CET 2009

On Tue, Nov 17, 2009 at 4:19 PM, Peng Yu <pengyu.ut at> wrote:
> There are some assertion code (testing if a condition is false, if it
> is false, raise an Error object) in my python, which is useful when I
> test my package.  But such case would never occur when in the produce
> code. If I keep them in if statement, it will take some runtime. I'm
> wondering what is the practice that take care of the assertion code in
> python.

Read the manual:

"In the current implementation, the built-in variable __debug__ is
True under normal circumstances, False when optimization is requested
(command line option -O). The current code generator emits no code for
an assert statement when optimization is requested at compile time."


More information about the Python-list mailing list