Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Matthew Fitzgibbons <elessar@xxxxxxxxxx>
- Date: Thu, 31 Jul 2008 13:04:05 -0600
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
.
- References:
- Attack a sacred Python Cow
- From: Jordan
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Erik Max Francis
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Russ P.
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Heiko Wundram
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Russ P.
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Matthew Fitzgibbons
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
- From: Steven D'Aprano
- Attack a sacred Python Cow
- Prev by Date: Re: Hobbyist - Python vs. other languages
- Next by Date: Re: Boolean tests [was Re: Attack a sacred Python Cow]
- Previous by thread: Re: Boolean tests [was Re: Attack a sacred Python Cow]
- Next by thread: Re: Boolean tests [was Re: Attack a sacred Python Cow]
- Index(es):
Relevant Pages
|