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


Groups > comp.lang.python > #17147

boolean from a function

Date 2011-12-13 16:24 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
Subject boolean from a function
Newsgroups comp.lang.python
Message-ID <mailman.3604.1323793451.27778.python-list@python.org> (permalink)

Show all headers | View raw


I'm not sure for how long I had this bug, and I could not understand the 
problem.

I had a function which would return a boolean

def func_bool():
     if x:
         return True
     else: return False

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...

Back to comp.lang.python | Previous | NextNext 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