Jean-Michel Pichavant wrote:
Peng Yu 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.
Would never occur ? You can't use 'would' and 'never' in the same sentence. That is the kind of concect that make (to me) asserts diffcult to use. I personally never use asserts in python, cause I will end up handling with asserts what I should in fact handle properly in what you call the production code.

Anyway that does not answer your question I'm sorry to be off topic, 'tis just a thought. Simon gave you the proper answer.

Jean-Michel

Actually, if an assert statement is never raised in production code irrespective of the condition (even in case of malicious inputs), it is the correct use of assert statement. The difficulty is in proving that it is impossible to raise the assert. In most cases it is impossible to prove and we just turn off assert when we're quite confident that it is bug-free enough.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to