PEP 285: Adding a bool type
David Eppstein
eppstein at ics.uci.edu
Sat Mar 30 13:04:17 EST 2002
More information about the Python-list mailing list
Sat Mar 30 13:04:17 EST 2002
- Previous message (by thread): PEP 285: Adding a bool type
- Next message (by thread): PEP 285: Adding a bool type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <a84t0v$k7u$1 at inputplus.demon.co.uk>, ralph at inputplus.demon.co.uk (Ralph Corderoy) wrote: > > > 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. If that's what he's doing, int(bool(x)) is still much clearer than the alternative bool-to-int expressions that (as he says) reek. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
- Previous message (by thread): PEP 285: Adding a bool type
- Next message (by thread): PEP 285: Adding a bool type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list