Clarity vs. code reuse/generality

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jul 3 14:03:07 EDT 2009


On Fri, 03 Jul 2009 16:19:22 +0000, kj wrote:

> In <mGo3m.591$P5.76 at nwrddc02.gnilink.net> Alan G Isaac
> <alan.isaac at 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.


-- 
Steven



More information about the Python-list mailing list