epiphany

Roy Smith roy at panix.com
Thu Apr 25 09:15:01 EDT 2013


In article <51792710$0$29977$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> > It also says, "Its truth value is true".  Why would they document that
> > fact if you weren't supposed to use it as a boolean operand?
> 
> You can use *anything* in Python in a boolean context. That's a language 
> feature: all objects are either truthy or falsey. As for why it is 
> documented for NotImplemented, I guess that's because some people might 
> guess that it is falsey, like None.

That was part of what added the epiphanality to the experience.  My 
first guess was exactly as you say, that bool(NotImplemented) would be 
false.  Once I discovered that it was true, the rest immediately fell 
into place and many lines of code got replaced by the simple:

    return all(r(...) for r in rules)
                  ^
                  |
                  +---- stuff that I'm not showing goes here :-)



More information about the Python-list mailing list