PEP 285: Adding a bool type
Tim Peters
tim.one at comcast.net
Sat Mar 30 17:44:12 EST 2002
[Guido, on why operator.truth() should change to return True/False]
> Tim must be missing something. The obvious way to turn a bool b into
> an int is int(b).
It's also an incorrect way for me, because I meant "true/false expression"
in the way Python has always meant it, e.g. operator.truth([]) == 0, but
int([]) raises an exception. The alternative int(bool(b)) is not obvious
(else you would have thought of it first <wink>), and becomes needed only if
operator.truth() is changed.
> Having to import the obscure 'operator' module for this purpose is
> backwards.
Under the PEP it's extremely easy to get a bool result (bool(b)), so I favor
presuming that anyone bothering to use operator.truth() will do so because
bool() doesn't do what they want; and if they're using truth() in 2.2, are
doing so because they specifically want a 0/1 result.
> (IMO there's almost *never* a reason to import that module anyway.)
That's not a reason to change what it does -- people who do import it
generally know exactly what they're doing, or have no idea <wink>.
More information about the Python-list
mailing list