Anything equivalent to cassert in C++?

Simon Forman sajmikins at gmail.com
Tue Nov 17 17:01:38 EST 2009


On Tue, Nov 17, 2009 at 4:19 PM, Peng Yu <pengyu.ut at gmail.com> 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:

http://docs.python.org/reference/simple_stmts.html#the-assert-statement

"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."

HTH,
~Simon



More information about the Python-list mailing list