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


Groups > comp.lang.python > #82555

Re: is_<whatever_you_are_testing_for> as method or property?

References (1 earlier) <CAPTjJmojWeyB_bv-6Rjzkno6Cb7NiUKo7rt4Th6fvNPOsGv_jQ@mail.gmail.com> <CABUeae9ukrw8iYan+iFj_6-V7LT0MVm+heVDWv7zEkqEAMim+g@mail.gmail.com> <CAPTjJmpOX2pEgJM7AgOWeOge5+H=QNUd2KH9nKC34PBVJSDUYQ@mail.gmail.com> <mailman.16927.1418418244.18130.python-list@python.org> <548c21e2$0$13005$c3e8da3$5496439d@news.astraweb.com>
From Mateusz Loskot <mateusz@loskot.net>
Date 2014-12-15 10:56 +0100
Subject Re: is_<whatever_you_are_testing_for> as method or property?
Newsgroups comp.lang.python
Message-ID <mailman.16978.1418637454.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 13 December 2014 at 12:24, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Mateusz Loskot 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:
> [...]
>> 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.
>
> If the calculation is cheap and fast and "feels like" getting/setting an
> attribute, then use property.
>
> If the calculation is expensive, or might fail, then use explicit
> getter/setter methods.
>
> I'm afraid that there is no objective way to tell when something "feels
> like" an attribute. That depends partly on the class you are dealing with,
> and partly on personal taste.

That confirms my now updated, thanks to this thread, understanding of
that issue.

Thanks all!

Best regards,
-- 
Mateusz  Loskot, http://mateusz.loskot.net

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


Thread

Re: is_<whatever_you_are_testing_for> as method or property? Mateusz Loskot <mateusz@loskot.net> - 2014-12-12 22:03 +0100
  Re: is_<whatever_you_are_testing_for> as method or property? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-13 22:24 +1100
    Re: is_<whatever_you_are_testing_for> as method or property? Mateusz Loskot <mateusz@loskot.net> - 2014-12-15 10:56 +0100

csiph-web