Re: boolean from a function
- From: Andrea Crotti <andrea.crotti.0@xxxxxxxxx>
- Date: Wed, 14 Dec 2011 09:42:08 +0000
On 12/13/2011 11:37 PM, Steven D'Aprano wrote:
No no it was just to show the pattern, it wasn't the actual code.
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.
I don't like to have useless indirections, so I wouldn't do that...
I like the idea of the property (from Duncan Booth) but the thing is that that function
looks like it's doing something (from its name), it's not just a simple property.
In the case of the square
class Sq(object):
def __init__(self, x, y):
self.x = x
self.y
It makes perfect sense to have "area" as a property, because you can either compute
it and cache it or compute it on demand.
It feels a bit less natural to create a property on something that is less simple than that imho..
.
- References:
- boolean from a function
- From: Andrea Crotti
- Re: boolean from a function
- From: Steven D'Aprano
- boolean from a function
- Prev by Date: Re: xml, minidom, ElementTree
- Next by Date: Re: AttributeError in "with" statement (3.2.2)
- Previous by thread: Re: boolean from a function
- Next by thread: Re: boolean from a function
- Index(es):
Relevant Pages
|