Steve Holden wrote: > > I'm actually surprised nothing like that already exists in the > > language > > (maybe it does and I'm just missing it), since being able to test > > for > > truth in the same way that if ...: would seem a common application. > > ...since operator.truth() already does it. See, the time machine flies > into > action yet again! Guido *knew* you would want this. Can we take it you > are > mollified? Well, there you go. I said maybe it was there and I was missing it. > I believe it has now been pointed out several times that this > would*not* be > equivalent to the C conditional operator, because it evaluates both > expressions before selecting them according to the truth value. Close, > but > no cigar. Yes, that's true. It's certainly good enough for most purposes, though, where either the expressions don't have side effects or if they do you expect them both to be evaluated anyway. I primarily wanted to use the functional for switching between simple values, viz.: print "The flag is %s" % ['false', 'true'][bool(flag)] > Anyone who has messed around with multi-valued logics (even the > three-valued > TRUE, FALSE, NULL of SQL) will tell you that you had better sharpen > your > mind before you tangle with them. The law of the divided middle is so > ensconced in most people's thinking that it's *very* difficult to chop > N-valued logic where N>2. Sure. Another reason why there's no reason for it to be included in the language proper. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ 'Tis man's to fight, but Heaven's to give success. \__/ Homer Crank Dot Net / http://www.crank.net/ Cranks, crackpots, kooks, & loons on the Net.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4