Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105373
| Path | csiph.com!news.mixmin.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | "Joseph L. Casale" <jcasale@activenetwerx.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Static caching property |
| Date | Mon, 21 Mar 2016 16:49:47 +0000 |
| Lines | 46 |
| Message-ID | <mailman.447.1458579150.12893.python-list@python.org> (permalink) |
| References | <35a5c4206a0c40e584d62d5d37b068b3@activenetwerx.com> <56f0230e$0$1616$c3e8da3$5496439d@news.astraweb.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de tCJbJiDdowwJRXBP2Uz3YAg0ZXEyQRALXH0WMMyGLu0Q== |
| Return-Path | <jcasale@activenetwerx.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'static': 0.03; 'api': 0.09; '@property': 0.09; 'descriptor': 0.09; 'instance.': 0.09; 'specific.': 0.09; 'def': 0.13; 'java,': 0.15; '999': 0.16; 'attribute:': 0.16; 'deferred': 0.16; 'received:172.18.0': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'test()': 0.16; 'yup,': 0.16; 'refers': 0.18; "shouldn't": 0.18; '(in': 0.18; 'to:name:python-list@python.org': 0.20; 'java': 0.22; 'header:In- Reply-To:1': 0.24; 'sense': 0.26; 'var': 0.27; 'callable': 0.29; 'itself,': 0.29; 'classes': 0.30; 'non': 0.32; 'expensive': 0.32; 'class': 0.33; 'instances': 0.33; 'gets': 0.35; 'clear': 0.35; 'instance': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'thanks': 0.37; 'associated': 0.38; 'end': 0.39; 'test': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'execution,': 0.91 |
| X-Authority-Analysis | v=2.1 cv=FIq7v7cs c=1 sm=1 tr=0 a=g3mLq75WYuDrh3Lt0JSDww==:117 a=g3mLq75WYuDrh3Lt0JSDww==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=P90J6pEA2ccA:10 a=8nJEP1OIZ-IA:10 a=7OsogOcEt9IA:10 a=MWWXQqbeSIeVeF8QtU0A:9 a=wPNLvfGTeEIA:10 |
| X-Spam-Checker-Version | SpamAssassin 3.4.0 (2014-02-07) on mail.activenetwerx.com |
| X-Spam-Level | |
| X-Spam-Status | No, score=-1.0 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 |
| Thread-Topic | Static caching property |
| Thread-Index | AQHRg4dpC97vHCaJwEm/OBao3y7fUJ9kGfXygAAA4Ok= |
| In-Reply-To | <56f0230e$0$1616$c3e8da3$5496439d@news.astraweb.com> |
| Accept-Language | en-CA, en-US |
| Content-Language | en-CA |
| X-MS-Has-Attach | |
| X-MS-TNEF-Correlator | |
| x-originating-ip | [172.18.0.4] |
| X-CMAE-Envelope | MS4wfOakQBgc3O6lxT4Izpc6ibf9JEMyzrrt8qE7Yl3FEeVUUkYuQtMxPiAFl2j2fk8UjHpKj2kzPmjX6L1Y9T9KRMKwV6/Rn03p078dlbGttdVBh0m/K1JR cE/YAm768+FDN42V8svVKtBXBXPWP8d2PFBiWv7CgzzBuSV5xyl/J67CkOYdmX3pqAX9AWbn0EjODA== |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:105373 |
Show key headers only | View raw
> I think Joseph is using "static" in the Java sense of being associated with > the class rather than an instance. (In Java, members of classes must be > known at compile-time.) Yup, so a single value on the class itself, not instance specific. > But what you can do is have the property refer to a class attribute: > > > py> class Test(object): > ... _private = 999 > ... @property > ... def x(self): > ... return type(self)._private > ... @x.setter > ... def x(self, value): > ... type(self)._private = value > ... > py> a = Test() > py> b = Test() > py> c = Test() > py> a.x > 999 > py> b.x = 50 > py> c.x > 50 > py> a.x > 50 Right, but _private refers to an api call that is expensive and may not even be accessed, so while I may new up three instances of Test across a, b and c, if none of those end up accessing var x, it shouldn't get fetched. Without some deferred execution, if the value of _private is a callable whose return value is what I am interested in, it gets invoked the moment the class is compiled. In the non static sense this is trivial to accomplish with the descriptor protocol, I am just not clear for the static sense. Thanks Ian and Steven, jlc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Static caching property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-21 10:15 -0600
Re: Static caching property Steven D'Aprano <steve@pearwood.info> - 2016-03-22 03:36 +1100
Re: Static caching property "Joseph L. Casale" <jcasale@activenetwerx.com> - 2016-03-21 16:49 +0000
Re: Static caching property Chris Angelico <rosuav@gmail.com> - 2016-03-22 03:54 +1100
Re: Static caching property "Joseph L. Casale" <jcasale@activenetwerx.com> - 2016-03-21 17:03 +0000
Re: Static caching property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-21 11:44 -0600
Re: Static caching property Ethan Furman <ethan@stoneleaf.us> - 2016-03-21 10:45 -0700
Re: Static caching property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-21 11:48 -0600
Re: Static caching property Steven D'Aprano <steve@pearwood.info> - 2016-03-22 11:05 +1100
Re: Static caching property Chris Angelico <rosuav@gmail.com> - 2016-03-22 11:15 +1100
Re: Static caching property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-22 07:30 -0600
csiph-web