Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82468
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'talks': 0.03; 'subsequent': 0.05; 'assign': 0.07; 'attribute': 0.07; 'mentioned,': 0.07; 'method.': 0.07; 'plenty': 0.07; 'method,': 0.09; 'style.': 0.09; 'subject:method': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; "wouldn't": 0.14; 'changes': 0.15; 'agreed,': 0.16; 'arbitrarily': 0.16; 'assignment.': 0.16; 'attribute,': 0.16; 'attributes.': 0.16; 'boolean': 0.16; 'effect.': 0.16; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'read-write': 0.16; 'simplest': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'discussion': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'fine': 0.24; 'java': 0.24; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'pass': 0.26; 'asking': 0.27; 'certain': 0.27; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'related': 0.29; 'dec': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; 'default,': 0.31; 'class': 0.32; 'this.': 0.32; 'cases': 0.33; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; "can't": 0.35; 'classes': 0.35; 'december': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'doing': 0.36; 'method': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'so,': 0.37; 'starting': 0.37; 'fact': 0.38; 'pm,': 0.38; '12,': 0.39; 'realize': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'most': 0.60; 'new': 0.61; 'simply': 0.61; 'simple': 0.61; 'such': 0.63; 'more': 0.64; 'different': 0.65; 'worth': 0.66; 'here': 0.66; 'direct': 0.67; 'side': 0.67; 'between': 0.67; 'default': 0.69; 'obvious': 0.74; 'capture': 0.91; '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=FtSQtfnc4ZSuxOlDvzf+KjCWczl0/t5WhUHtiEnxNb0=; b=mCiFSoUcqvJ7O6/6DdgQsOaZUQWe+7iDY0UmGX7Co2pfPxUpI5E5Ux9ZGc2DUImfv0 PbBeZ+K42+2Y3hbWSl13I83CHd+PjybO78bNJ344aWKKkXQ+YQo1WmMYymivHX0hU+WH TdtupOP3+2LVVPA3QQ5bANXZAwD3Z/ILsAgElGmNpMRieWCQ6G6pewiM9LhM0VCC3R7z /Rq12obUxBKULblVFJVCQne7ok8/xQpNrxCUGsFhDH72mZXhi4z2NHVFg+nlULUN3zlx 98JGYUTqT6jnr2wMhvKsdTSoI6Ha36egmtMYvUXhYYGL8ldHigMwf616Ip/xOHGy5qhS CPFQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.94.14 with SMTP id z14mr17670411icm.59.1418418876052; Fri, 12 Dec 2014 13:14:36 -0800 (PST) |
| In-Reply-To | <CABUeae-gKsViJt_bD78rZONDeOHVQ4EG82VDpteeuRpcs+W62w@mail.gmail.com> |
| References | <CABUeae-rNeN_dGgkgauNr+-qChXvkgenBmgLbFioe+JDqiT+Hg@mail.gmail.com> <CAPTjJmojWeyB_bv-6Rjzkno6Cb7NiUKo7rt4Th6fvNPOsGv_jQ@mail.gmail.com> <CABUeae9ukrw8iYan+iFj_6-V7LT0MVm+heVDWv7zEkqEAMim+g@mail.gmail.com> <CAPTjJmpOX2pEgJM7AgOWeOge5+H=QNUd2KH9nKC34PBVJSDUYQ@mail.gmail.com> <CABUeae-gKsViJt_bD78rZONDeOHVQ4EG82VDpteeuRpcs+W62w@mail.gmail.com> |
| Date | Sat, 13 Dec 2014 08:14:35 +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.16928.1418418885.18130.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418418885 news.xs4all.nl 2900 [2001:888:2000:d::a6]:57876 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82468 |
Show key headers only | View raw
On Sat, Dec 13, 2014 at 8:03 AM, Mateusz Loskot <mateusz@loskot.net> wrote: > On 12 December 2014 at 12:26, Chris Angelico <rosuav@gmail.com> wrote: >> On Fri, Dec 12, 2014 at 10:21 PM, Mateusz Loskot <mateusz@loskot.net> wrote: >>> I've got several cases which are not obvious to me. >>> For instance, class Foo has a boolean attribute, read-write, >>> which I see a couple of realisations for possible: >>> >> >> 0) Attribute only. >> >> class Foo: >> pass >> >> Foo().default = True >> >> Unless you need something more than this, go with this style. Much simpler. > > > Agreed, in general, but if the question was related to such simple case, > I wouldn't bother asking it. > > I mentioned, setting the new value involves more changes to Foo() > instance, so i's not possible to capture it with just an assignment. > Hence, the discussion between property vs method. It's still worth mentioning, for completeness. Plenty of people come from C++ or Java and simply don't realize that direct attribute access makes fine sense. Your statement here talks about a read-write boolean attribute, so starting off with the simplest way of doing that - an actual attribute - emphasizes the commonness of this. So, your subsequent design decisions are based around the fact that you cannot simply assign to .default and have it do the right thing. Are you even able to set default to False? For instance, you might have a system where there must always be one "default", and so you can't make this one not-default, but you could make a different one the default, which will un-default-ify this one as a side effect. In that case, a "make_default()" method makes the most sense. But if you can independently and cheaply set any instance's default flag, you could have the actual attribute, and then a set_default() method, which updates it. Plenty of Python classes recommend not arbitrarily altering certain attributes. ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: is_<whatever_you_are_testing_for> as method or property? Chris Angelico <rosuav@gmail.com> - 2014-12-13 08:14 +1100
csiph-web