PEP 285: Adding a bool type

Chris Barker Chris.Barker at noaa.gov
Tue Apr 9 16:37:22 EDT 2002


"Guido van Rossum" <guido at python.org> wrote in message
> I found a lot of
> disagreement on what people consider a "real" Boolean type.  I did find
> wide agreement on something that I had myself taken for granted, but which
> some proponents of "real" Booleans were challenging: the usefulness of
> Python's ability to test almost *any* object for its truth value, what
> Laura calls something/nothing.

I am one of those people, and I do see the "usefulness of Python's
ability to test almost *any* object for its truth value". It is
fantasically useful. What I don't like is that it is implicit, rather
than explicit.

I would love being able to do:

if bool(anyobject):  #(or maybe istrue(), or something like that)
	whatever

What I don't like so much is:

if anyobject:
	whatever

because unless anyobject is of a class I have defined myself, Python has
decided ahead of time what an untrue (or nothing) value is for that
object. That means I can't have a function return an integer, for
example, and have it evaluate as true, when a zero is not "nothing" in
this context.

and yes, I know that it is WAY too late in Python develpment to
impliment this, and I do love the laguage anyway.

By the way, can I now subclass from int, and use objects of the
resulting class as an index, and also redefine __nonzero__ or whatever,
so that I can get a 0 to be both an index and evaluate as true? I'm not
running 2.2, so I can't test it myslef. If I can, then I guess I can
achieve most of what I want, but I'm sure it would confuse people if
anyone else were to use my class!

-Chris





-- 
Christopher Barker, Ph.D.
Oceanographer
                                    		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the Python-list mailing list