Re: boolean from a function

2011-12-14 Thread Andrea Crotti
On 12/13/2011 11:37 PM, Steven D'Aprano wrote: x is a global? Poor design. But in any case, instead of an explicit if...else block, the canonical way to convert an arbitrary object to True/ False is with bool: def func_bool(): return bool(x) But you don't need it. See below. No no it

Re: boolean from a function

2011-12-13 Thread Steven D'Aprano
On Tue, 13 Dec 2011 16:24:05 +, Andrea Crotti wrote: > 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 x is a global? Poor

Re: boolean from a function

2011-12-13 Thread Ethan Furman
Andrea Crotti wrote: 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 qu

Re: boolean from a function

2011-12-13 Thread Duncan Booth
Andrea Crotti wrote: > 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: >

Re: boolean from a function

2011-12-13 Thread Grant Edwards
On 2011-12-13, Andrea Crotti 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)

boolean from a function

2011-12-13 Thread Andrea Crotti
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