PEP 285: Adding a bool type
Guido van Rossum
guido at python.org
Sat Mar 30 08:38:00 EST 2002
> [Guido]
> >> 5) Should operator.truth(x) return an int or a bool. Tim Peters
> >> believes it should return an int because it's been documented
> >> as such.
>
> [Ralph Corderoy]
> > Unlike Tim to produce such a poor reason. Has he been paraphrased a
> > little too much?
[Tim]
> 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.)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list