boolean from a function
Andrea Crotti
andrea.crotti.0 at gmail.com
Wed Dec 14 04:42:08 EST 2011
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 was just to show the pattern, it wasn't the actual code.
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..
More information about the Python-list
mailing list