Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17188
| Date | 2011-12-14 09:42 +0000 |
|---|---|
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
| Subject | Re: boolean from a function |
| References | <mailman.3604.1323793451.27778.python-list@python.org> <4ee7e1a4$0$29979$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3629.1323855732.27778.python-list@python.org> (permalink) |
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..
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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