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


Groups > comp.lang.python > #82387

Re: is_<whatever_you_are_testing_for> as method or property?

References <CABUeae-rNeN_dGgkgauNr+-qChXvkgenBmgLbFioe+JDqiT+Hg@mail.gmail.com> <CAPTjJmojWeyB_bv-6Rjzkno6Cb7NiUKo7rt4Th6fvNPOsGv_jQ@mail.gmail.com> <857fxxhnx8.fsf@benfinney.id.au>
Date 2014-12-12 08:49 +1100
Subject Re: is_<whatever_you_are_testing_for> as method or property?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16874.1418334577.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Dec 12, 2014 at 8:33 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Chris Angelico <rosuav@gmail.com> writes:
>
>> A property should be used if what you're creating is "virtually an
>> attribute".
>
> Methods are attributes. Are you distinguishing here between “callable
> attribute” versus “non-callable attribute”?

I'm talking conceptually here. You can, for instance, have a stat
object which has attribute for the file size and owner, and then it
makes equal sense to have an "is_dir" attribute; but that one might be
a property, calculated from the file mode. It makes logical design
sense for it to be an attribute with the value right there, so it
makes design sense for it to be a property. On the other hand, a
string will not normally have, as an attribute, a lower-case version
of itself, so it makes better sense for that to be a callable method
rather than a property.

Yes, properties and methods are attributes. That's a technical detail
that has nothing to do with the design question of "should this be a
property or 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 08:49 +1100

csiph-web