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


Groups > comp.lang.python > #82370

Re: is_<whatever_you_are_testing_for> as method or property?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'attribute': 0.07; 'method.': 0.07; 'subject:method': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '@property': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'cc:2**0': 0.24; 'define': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'class': 0.32; 'fri,': 0.33; 'sense': 0.34; 'something': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'subject:?': 0.36; 'should': 0.36; '12,': 0.39; 'simply': 0.61; "you're": 0.61; 'subject:skip:w 20': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=dSnBAiRAMI/LEd9QEv/7Kg8rQRLZqEzZwPHGult2A9I=; b=VvQS+we9Zo4T+TaeVwL/lq72NdhjwTxo7nhQNuGp59ybTBL2OZcffVNVYiUZ++Xmf1 /kpT8s3H1ty1gNUvW74C9l8QqWJNj4Mrbg60523fKzC/84XeW8ZrtJoOYxsoJyPyODnw eCIrCQyyJxuJJl8MZwwg29zMbTISOZW8VlQLEKvyy+qYyNyb75w9GkX6yZtyiyqsf5fI aiuAYaAm9GA024UQgD55knFQNz4ZZJEgAW9nPPvAui6H/sICrSCUa6GRWtKP83S+kYQk tviK9G9/WzpuenJlw1NDEu0L6pP3Y/UWJs2Fn004AbzjIuArgtEW3MtNgGrWX5XEs+AO 9p6Q==
MIME-Version 1.0
X-Received by 10.50.82.97 with SMTP id h1mr328375igy.14.1418322051673; Thu, 11 Dec 2014 10:20:51 -0800 (PST)
In-Reply-To <CABUeae-rNeN_dGgkgauNr+-qChXvkgenBmgLbFioe+JDqiT+Hg@mail.gmail.com>
References <CABUeae-rNeN_dGgkgauNr+-qChXvkgenBmgLbFioe+JDqiT+Hg@mail.gmail.com>
Date Fri, 12 Dec 2014 05:20:51 +1100
Subject Re: is_<whatever_you_are_testing_for> as method or property?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16862.1418322408.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418322408 news.xs4all.nl 2834 [2001:888:2000:d::a6]:43260
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3617
X-Received-Body-CRC 617149669
Xref csiph.com comp.lang.python:82370

Show key headers only | View raw


On Fri, Dec 12, 2014 at 4:34 AM, Mateusz Loskot <mateusz@loskot.net> wrote:
> If a class member function simply tests something and
> returns a b::oolean call it
>
> def is_<whatever_you_are_testing_for>():
>  pass
>
> like 'is_even'.
>
> Should I define it as a classic method
>
> def is_even(self):
>     pass
>
> or as a property
>
> @property
> def is_even(self):
>     pass

A property should be used if what you're creating is "virtually an
attribute". If it would make sense to have an attribute is_even, then
a property is_even makes sense. If in doubt, go with a method.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: is_<whatever_you_are_testing_for> as method or property? Chris Angelico <rosuav@gmail.com> - 2014-12-12 05:20 +1100

csiph-web