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

Hyuga hyugaricdeau at gmail.com
Wed Jul 30 10:10:34 EDT 2008


On Jul 30, 3:53 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
> Fair enough. I have no dog in this particular fight. I just think it
> wouldn't hurt to add an "isempty()" or "isnonempty()" method to the
> list type, and let people use it if they wish, or continue using "if
> x" if that's what they prefer.

Go right on ahead.  You could implement it like this:

class superenhancedlist(list):
    def isempty(self):
        return not self

>>> a = superenhancedlist()
>>> a.isempty()
True
>>> a.append(1)
>>> a.isempty()
False

Amazingly useful!  Go ahead and use that in all your code.  Anyone
else who comes along and looks at it or tries to maintain it will
really love you for it.



More information about the Python-list mailing list