Boolean tests [was Re: Attack a sacred Python Cow]

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Jul 29 19:39:06 EDT 2008


On Tue, 29 Jul 2008 21:15:12 +0100, Matthew Woodcraft wrote:

> Steven D'Aprano  <steven at REMOVE.THIS.cybersource.com.au> wrote:
>> "if x" is completely type agnostic. You can pass an object of any type
>> to it, and it will work. (Excluding objects with buggy methods,
>> naturally.)
> 
> There are many circumstances where if a parameter is None I'd rather get
> an exception than have the code carry on with the 'empty container'
> branch (and silently give me a meaningless result).

Sure. The way I'd handle that is test for None at the start of the 
function, and raise an error there, rather than deal with it at some 
arbitrary part of the function body.


-- 
Steven



More information about the Python-list mailing list