PEP 285: Adding a bool type
Ralph Corderoy
ralph at inputplus.demon.co.uk
Sat Mar 30 12:35:27 EST 2002
Hi Guido,
> > Not in Guido's eyes <wink>. We don't need 3 equivalent ways to
> > turn an arbitrary expression into a bool ("bool(x)" same-as "not
> > not (x)" same-as "truth(x)"). *Especially* if str(bool) and
> > repr(bool) produce 'True' and 'False', people have a legitimate
> > need to make an arbitrary true/false expression produce 0 and 1
> > too, if only to preserve 0/1-based true/false output.
> > operator.truth() has always been the best way to do exactly that.
> > Alternatives like "(boolexpr) + 0" and "(boolexpr) and 1 or 0" and
> > "(0, 1)[boolexpr]" reek in comparison.
>
> Tim must be missing something. The obvious way to turn a bool b into
> an int is int(b). Having to import the obscure 'operator' module for
> this purpose is backwards. (IMO there's almost *never* a reason to
> import that module anyway.)
I thought Tim was trying to map a range of integer values onto just 0
and 1 as ints, not False and True, where as you're suggesting he just
wants to get an int from a boolean. I think he has an expression like
day_of_month, e.g. 30, and wants a 0 or 1 from it.
I could easily be wrong here.
Ralph.
More information about the Python-list
mailing list