Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17154

Re: boolean from a function

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: boolean from a function
Date 2011-12-13 17:20 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <jc81h3$k31$1@reader1.panix.com> (permalink)
References <mailman.3604.1323793451.27778.python-list@python.org>

Show all headers | View raw


On 2011-12-13, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:

> Now somewhere else I had
>
> if func_bool:
>      # do something
>
> I could not quite understand why it was always true, until I finally
> noticed that the () were missing. Is there some tool to avoid these
> stupid mistakes? (pylint doesn't warn me on that) I don't think I
> will ever (or almost) have to use a function as a boolean, instead of
> its return value...

FWIW, I have do use the truth value of a function (rather than it's
return value) when writing code that uses callbacks:

def foo(callback=None):
    # do some stuff
    if callback:
        callback()
    # do some more stuff        

It probably would be better to use "if callback is not None:", but I
find I usually skip "is not None".
    
-- 
Grant Edwards               grant.b.edwards        Yow! Will it improve my
                                  at               CASH FLOW?
                              gmail.com            

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

boolean from a function Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-13 16:24 +0000
  Re: boolean from a function Grant Edwards <invalid@invalid.invalid> - 2011-12-13 17:20 +0000
  Re: boolean from a function Duncan Booth <duncan.booth@invalid.invalid> - 2011-12-13 17:42 +0000
  Re: boolean from a function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-13 23:37 +0000
    Re: boolean from a function Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-14 09:42 +0000

csiph-web