Steven D'Aprano wrote:
On Fri, 03 Jul 2009 16:19:22 +0000, kj wrote:

In <mgo3m.591$p5...@nwrddc02.gnilink.net> Alan G Isaac
<alan.is...@gmail.com> writes:

1. Don't use assertions to test argument values!
Out of curiosity, where does this come from?

Assertions are disabled when you run Python with the -O (optimise) flag. If you rely on assertions to verify data, then any time the user runs python with -O your code will be running without error checking.

assert should be used to verify program logic, not to sanitize data.

In other words, assertions should never happen, whereas your assertions could easily happen with 'bad' input. An example of program logic assertion would be 'assert <loop-invariant>' at the top of the loop. That would be useful for development, but would not be needed for production use of tested code.

tjr


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to