which

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Feb 5 17:19:11 EST 2010


On Fri, 05 Feb 2010 16:52:19 +0100, mk wrote:

> assert isinstance(cmd, basestring) or cmd is None, "cmd should be string
> or None"

Do not use assertions for input validation. That's not what they're for.

assert is compiled away when you run your code with the -O switch, which 
means that the test may never be made at all. You should limit assertions 
for testing "this can never happen" situations, verifying pre- and post-
conditions, checking the internal logic of your code, and similar.


See also:

http://nedbatchelder.com/text/assert.html


-- 
Steven



More information about the Python-list mailing list