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

Russ P. Russ.Paielli at gmail.com
Wed Jul 30 02:36:19 EDT 2008


On Jul 29, 11:16 pm, Erik Max Francis <m... at alcyone.com> wrote:
> Russ P. wrote:
> > On Jul 29, 10:33 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> >> On Jul 30, 1:15 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
>
> >>> Having said that, it would sure be nice to be able to write
> >>> if myList is not empty:
> >>> instead of
> >>> if len(myList) != 0:
> >> I can agree with this.
>
> > But I guess that could only work if there were only one empty list
> > that represents all empty lists (as there is only one actual "None").
> > I don't know if that makes sense or not.
>
> It really doesn't, since it presumably wouldn't apply to just list
> types.  There are plenty of other sequence types:  such as tuples,
> strings, or even arbitrary custom types.  Emptiness is a test for the
> value of an object, not a test for whether it is identical to another
> object, so this is a very misleading of the `is` operator, bordering on
> abuse.
>
> This syntax would make far less sense than the existing Boolean test.
>
> --
> Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/
>   San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
>    The doors of Heaven and Hell are adjacent and identical.
>     -- Nikos Kazantzakis

Now that's more reasonable. Note that I said, "it would be nice to be
able to write," not "this is how it should be done."

Come to think of it, shouldn't the list type have an "isempty" method?
Or does it?



More information about the Python-list mailing list