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


Groups > comp.lang.python > #17188

Re: boolean from a function

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.053
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'compute': 0.09; 'def': 0.13; 'cache': 0.15; 'block,': 0.16; 'name),': 0.16; 'subject:function': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'cc:addr:python-list': 0.16; "wouldn't": 0.17; 'wrote:': 0.18; 'convert': 0.19; 'cc:no real name:2**0': 0.20; 'header:In- Reply-To:1': 0.22; 'cc:2**0': 0.24; 'code.': 0.26; 'function': 0.27; "wasn't": 0.28; 'bit': 0.28; 'explicit': 0.29; 'looks': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'class': 0.29; 'that...': 0.30; 'useless': 0.30; 'actual': 0.32; 'idea': 0.32; 'received:209.85.161.46': 0.32; 'received:mail- fx0-f46.google.com': 0.32; 'message-id:@gmail.com': 0.33; 'header :User-Agent:1': 0.33; 'instead': 0.33; 'object': 0.33; 'it.': 0.34; 'something': 0.35; 'received:209.85.161': 0.36; '(from': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'skip:_ 10': 0.37; 'doing': 0.38; 'received:10.0.0': 0.38; 'steven': 0.38; 'received:209.85': 0.38; 'subject:from': 0.38; 'either': 0.39; "it's": 0.40; 'received:209': 0.40; 'property': 0.63; 'perfect': 0.64; 'below.': 0.66; 'natural': 0.66; 'square': 0.67; 'show': 0.67; 'design.': 0.73; '11:37': 0.84; 'canonical': 0.91; 'demand.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=L01HzxFtQVO32rJ5uB0rLgDPAe5UPvJO8cLWBjiUsrA=; b=Cxx7DtUQJUlYdLB/xJvTr58NSA/U0eAPXarCoA660pAbuBqsmkrx8ZZ6W+/kz0gx5/ Xl+goj+4xFkF5GK16tGYbZyXx3tvECvPZJ859f+fgkhcLuBPvOnSlJziRUuIJSodYT8V 1nhgWbte5yq+psh4XAfil6ShJQkDOQMdSYvKA=
Date Wed, 14 Dec 2011 09:42:08 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: boolean from a function
References <mailman.3604.1323793451.27778.python-list@python.org> <4ee7e1a4$0$29979$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <4ee7e1a4$0$29979$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3629.1323855732.27778.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323855732 news.xs4all.nl 6848 [2001:888:2000:d::a6]:56733
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17188

Show key headers only | View raw


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