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

Erik Max Francis max at alcyone.com
Wed Jul 30 09:55:43 CEST 2008


Russ P. wrote:

> On Jul 29, 11:36 pm, Erik Max Francis <m... at alcyone.com> wrote:
>> Russ P. wrote:
>>> Come to think of it, shouldn't the list type have an "isempty" method?
>>> Or does it?
>> Yes.  It's written:
>>
>>         if not aList:
>>             ...
> 
> As you know, that is not quite exactly the same thing. An "isempty"
> method would fail if aList were an integer, and such failure might be
> desirable if someone mistakenly had aList pointing to an integer.

If you're that concerned about what the type is, then you can do 
explicit typechecks.  Those are discouraged precisely because of 
Python's dynamism.  But knock yourself out.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   The actor is not quite a human being -- but then, who is?
    -- George Sanders



More information about the Python-list mailing list