Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52638
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.063 |
| X-Spam-Evidence | '*H*': 0.88; '*S*': 0.00; 'subject:Python': 0.06; 'self.data': 0.09; 'def': 0.12; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'wrote:': 0.18; 'primary': 0.26; 'header:In-Reply-To:1': 0.27; "d'aprano": 0.31; 'steven': 0.31; 'allows': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'add': 0.35; 'consistent': 0.36; 'data,': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'goal': 0.75; 'clearer': 0.84; 'received:50.22': 0.84; 'good,': 0.91 |
| Date | Sat, 17 Aug 2013 12:31:01 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| To | python-list@python.org |
| Subject | Re: Python getters and setters |
| In-Reply-To | <520fb04f$0$30000$c3e8da3$5496439d@news.astraweb.com> |
| References | <227bd47c-0e86-4d65-985f-e59aa4f25294@googlegroups.com> <520fb04f$0$30000$c3e8da3$5496439d@news.astraweb.com> |
| X-Mailer | Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| X-Get-Message-Sender-Via | boston.accountservergroup.com: none |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18.1376760589.23369.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1376760589 news.xs4all.nl 15997 [2001:888:2000:d::a6]:35629 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52638 |
Show key headers only | View raw
On 2013-08-17 17:18, Steven D'Aprano wrote:
> # Yes, this is good, consistent design
> len(myrecord.field)
> len(obj.data)
> len(data.value)
> len(collection[key])
I would also add that, if the primary goal of your class is to
encapsulate the data, you can do
class MyClass:
def __init__(self, ...):
self.data = []
def __len__(self):
return len(self.data)
which allows for the even clearer
my_obj = MyClass(...)
manipulate(my_obj)
if len(my_obj) > 42:
do_important_stuff()
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python getters and setters Fernando Saldanha <fsaldan1@gmail.com> - 2013-08-17 09:53 -0700
Re: Python getters and setters MRAB <python@mrabarnett.plus.com> - 2013-08-17 18:10 +0100
Re: Python getters and setters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 17:18 +0000
Re: Python getters and setters Tim Chase <python.list@tim.thechases.com> - 2013-08-17 12:31 -0500
Re: Python getters and setters Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-08-18 00:52 +0200
Re: Python getters and setters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 23:40 +0000
Re: Python getters and setters Chris Angelico <rosuav@gmail.com> - 2013-08-18 02:07 +0100
Re: Python getters and setters Fernando Saldanha <fsaldan1@gmail.com> - 2013-08-17 22:26 -0700
csiph-web