Boolean tests [was Re: Attack a sacred Python Cow]
Matthew Fitzgibbons
elessar at nienna.org
Thu Jul 31 15:04:05 EDT 2008
Steven D'Aprano wrote:
> On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote:
>
>> If you're expecting a list (and only a list)
>> then your point makes sense. 'if x' can get you into trouble if you
>> _don't_ want its polymorphism.
>
> "if x" is hardly unique in that way. If you're expecting a list, and only
> a list, "len(x) != 0" will get you in trouble if somebody passes a string
> or a dictionary. I don't see any reason why we should single out "if x"
> as dangerous in the face of invalid types. With the exception of the "is"
> and "is not" operators, nothing in Python is guaranteed to work with any
> imaginable object. Even print can fail, if the object's __str__ method
> raises an exception.
Forgot respond to this point. I heartily agree. :) I singled out 'if x'
only because that's the specific example under scrutiny. I think you and
I are pretty much in agreement.
-Matt
More information about the Python-list
mailing list