Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33415
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andriy.kornatskyy@live.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'error:': 0.05; 'none,': 0.05; 'skip:` 10': 0.05; 'present,': 0.07; 'welcome.': 0.07; 'python': 0.09; '(it': 0.09; '@property': 0.09; 'descriptor': 0.09; 'itself,': 0.09; 'satisfy': 0.09; 'def': 0.10; 'cases': 0.15; '33,': 0.16; 'attribute,': 0.16; 'class:': 0.16; 'descriptors': 0.16; 'object).': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'thu,': 0.17; '>>>': 0.18; 'to:name:python- list@python.org': 0.20; 'skip:- 40': 0.21; 'trying': 0.21; 'import': 0.21; 'thanks.': 0.21; 'do.': 0.21; '"",': 0.22; '15,': 0.23; 'to:2**1': 0.23; 'properties': 0.24; 'thus': 0.24; 'header :In-Reply-To:1': 0.25; '(most': 0.27; 'post': 0.28; 'cases.': 0.29; 'once.': 0.29; 'date:': 0.29; 'url:mailman': 0.29; 'class': 0.29; 'url:2012': 0.30; 'url:python': 0.32; 'file': 0.32; 'url:listinfo': 0.32; 'comments': 0.33; 'from:addr:live.com': 0.33; 'shorter': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'nature': 0.35; 'nov': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'subject:': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'thank': 0.36; 'itself': 0.37; 'being': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'object': 0.38; 'some': 0.38; 'shows': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'your': 0.60; 'email name :python-list': 0.62; 'relatively': 0.62; 'email addr:gmail.com': 0.63; 'url:blogspot': 0.64; 'results': 0.65; 'url:11': 0.71; 'special': 0.73; '99.9%': 0.84; 'demand,': 0.84; 'forced': 0.84; 'ian,': 0.84; 'candidate,': 0.95; 'demand': 0.96; 'charset:windows-1251': 0.97 |
| X-Originating-IP | [194.44.213.194] |
| From | Andriy Kornatskyy <andriy.kornatskyy@live.com> |
| To | <ian.g.kelly@gmail.com>, "python-list@python.org" <python-list@python.org> |
| Subject | RE: Lazy Attribute |
| Date | Fri, 16 Nov 2012 10:49:07 +0300 |
| Importance | Normal |
| In-Reply-To | <CALwzidnenqoEBmzY1Xoe-BfKV-v1crRV2CdeLj1asD1ZWBDo_A@mail.gmail.com> |
| References | <CALwzidnenqoEBmzY1Xoe-BfKV-v1crRV2CdeLj1asD1ZWBDo_A@mail.gmail.com> |
| Content-Type | text/plain; charset="windows-1251" |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 16 Nov 2012 07:49:06.0925 (UTC) FILETIME=[DB0B69D0:01CDC3CE] |
| 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.3734.1353052215.27098.python-list@python.org> (permalink) |
| Lines | 91 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1353052215 news.xs4all.nl 6916 [2001:888:2000:d::a6]:39499 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33415 |
Show key headers only | View raw
Ian, Thank you for the comments. > The name "attribute" is not very descriptive. Why not "lazy_attribute" instead? It just shorter and still descriptive. > If accessing the descriptor on the class object has no special > meaning, then the custom is to return the descriptor object itself, as > properties do. The lazy attribute, as a pattern, is designed to calculate something on demand, that being said means some `dynamic` nature must present, thus a class instance - object is a good candidate, while class itself is considered relatively `immutable`... of cause there might be extreme cases. > If accessing the descriptor on the class object has no special > meaning, then the custom is to return the descriptor object itself, as > properties do. If I would satisfy this, I will be forced to check for None 99.9% of the use cases (it is not None, being applied to an object). Thus it behaves as designed. Thanks. Andriy Kornatskyy ---------------------------------------- > From: ian.g.kelly@gmail.com > Date: Thu, 15 Nov 2012 15:24:40 -0700 > Subject: Re: Lazy Attribute > To: python-list@python.org > > On Thu, Nov 15, 2012 at 12:33 PM, Andriy Kornatskyy > <andriy.kornatskyy@live.com> wrote: > > > > A lazy attribute is an attribute that is calculated on demand and only once. > > > > The post below shows how you can use lazy attribute in your Python class: > > > > http://mindref.blogspot.com/2012/11/python-lazy-attribute.html > > > > Comments or suggestions are welcome. > > The name "attribute" is not very descriptive. Why not "lazy_attribute" instead? > > I note that trying to access the descriptor on the class object > results in an error: > > >>> from descriptors import attribute > >>> class Foo: > ... @attribute > ... def forty_two(self): > ... return 6 * 9 > ... > >>> Foo().forty_two > 54 > >>> Foo.forty_two > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File ".\descriptors.py", line 33, in __get__ > setattr(obj, f.__name__, val) > AttributeError: 'NoneType' object has no attribute 'forty_two' > > If accessing the descriptor on the class object has no special > meaning, then the custom is to return the descriptor object itself, as > properties do. > > >>> class Foo: > ... @property > ... def forty_two(self): > ... return 6 * 9 > ... > >>> Foo().forty_two > 54 > >>> Foo.forty_two > <property object at 0x0280AD80> > -- > http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
RE: Lazy Attribute Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-16 10:49 +0300
Re: Lazy Attribute Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-16 09:04 +0000
RE: Lazy Attribute Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-16 13:27 +0300
Re: Lazy Attribute Rouslan Korneychuk <rouslank@msn.com> - 2012-11-16 04:32 -0500
Re: Lazy Attribute Rouslan Korneychuk <rouslank@msn.com> - 2012-11-16 05:12 -0500
RE: Lazy Attribute Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-16 13:31 +0300
csiph-web