PEP 285: Adding a bool type

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Wed Apr 10 16:27:24 EDT 2002


Chris Barker <Chris.Barker at noaa.gov> wrote:
>I would love being able to do:
>
>if bool(anyobject):  #(or maybe istrue(), or something like that)
>	whatever
>
>What I don't like so much is:
>
>if anyobject:
>	whatever
>
>because unless anyobject is of a class I have defined myself, Python has
>decided ahead of time what an untrue (or nothing) value is for that
>object. 

If you do want Python's convention of untrue, then the above two do not make
much difference (if bool is implemented correctly).

If you want your own version of untrue, then you need

if my_predicate(anyobject):
    whatever

You still do not need

if bool(my_predicate(anyobject)):
    whatever

I don't see any situation that you need "if bool(some_expression)".

Huaiyu



More information about the Python-list mailing list