Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82387 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-12-12 08:49 +1100 |
| Last post | 2014-12-12 08:49 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: is_<whatever_you_are_testing_for> as method or property? Chris Angelico <rosuav@gmail.com> - 2014-12-12 08:49 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-12-12 08:49 +1100 |
| Subject | Re: is_<whatever_you_are_testing_for> as method or property? |
| Message-ID | <mailman.16874.1418334577.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web