A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-March/020833.html below:

[Python-Dev] For review: PEP 285: Adding a bool type

[Python-Dev] For review: PEP 285: Adding a bool typeTim Peters tim.one@comcast.net
Sat, 09 Mar 2002 15:27:10 -0500
[David Abrahams]
> ...I guess I can see why you're really intending that
>
>     >>> 0 or False
>     False
>
> but
>
>     >>> False or 0
>     0
>
> This sure rubs all my expectations for a bool the wrong way, though.

It has much more to do with expectations for what "and" and "or" do.  Note
that they're not "operators" in Python, they're control structures, and
cannot be overridden.  Don't mix bools with ints with control structures,
and you won't get surprised; "False or 0" returning 0 in Python is no more
surprising than that

if False:
    x = False
else:
    x = 0

sets x to 0, and *oodles* of code relies on that equivalence.

> I think I'd better just write my own assertion routine, as Guido
> suggested. I don't like non-obvious language constructs for something so
> simple (I'd mention ?: here but I don't need the bruises).

Na, do this:

def bool(e):
    return e and 'True' or 'False'

Then wrap your true/false expressions in bool() calls.  All assuming
x-version invariance is important to you.  When versions of Python before
2.3 become uninteresting, get rid of the bool() function (and so unmask the
builtin of the same name).




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