Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'yet.': 0.04; 'variables': 0.07; 'subject:help': 0.08; 'ambiguity': 0.09; 'references.': 0.09; 'repeated': 0.09; 'python': 0.11; '*class': 0.16; 'attributes,': 0.16; 'called.': 0.16; 'definition.': 0.16; 'normally,': 0.16; 'received:172.18.0': 0.16; ':-)': 0.16; 'do.': 0.18; 'thorough': 0.19; 'to:name:python-list@python.org': 0.22; 'decorators': 0.24; 'stick': 0.24; "haven't": 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'see,': 0.30; 'work.': 0.31; 'enjoyed': 0.31; 'loads': 0.31; 'ordinary': 0.31; 'class': 0.32; 'know.': 0.32; 'stuff': 0.32; 'regular': 0.32; 'run': 0.32; "can't": 0.35; 'classes': 0.35; 'but': 0.35; 'functions.': 0.36; 'done': 0.36; "didn't": 0.36; 'method': 0.36; 'thanks': 0.36; "i'll": 0.36; 'example,': 0.37; 'being': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:unknown': 0.61; 'utilize': 0.61; 'first': 0.61; 'more': 0.64; 'here': 0.66; 'fantastic': 0.74; 'other.': 0.75; 'and\xa0': 0.84; 'guessed': 0.84; 'guideline': 0.84; 'is\xa0': 0.84; 'yet?': 0.84 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=SNukfclIDc7GjKe+LHtSoPUBJt/gHPuqMk7EpfoOdzs= c=1 sm=1 a=CRTDazI5n6YA:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=8nJEP1OIZ-IA:10 a=xqWC_Br6kY4A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=0fULB5yaFHI6-8pY3sMA:9 a=wPNLvfGTeEIA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 From: "Joseph L. Casale" To: "python-list@python.org" Subject: RE: Decorator help Thread-Topic: Decorator help Thread-Index: AQHOK0L9GDgWeiUVSEqnSm5Oit30Vpi+7nsc Date: Sun, 31 Mar 2013 00:06:01 +0000 References: , <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.18.0.200] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364688371 news.xs4all.nl 6982 [2001:888:2000:d::a6]:51289 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42354 > When you say "class vars", do you mean variables which hold classes?=0A= =0A= =0A= You guessed correctly, and thanks for pointing out the ambiguity in my refe= rences.=0A= =0A= =0A= > The one doesn't follow from the other. Writing decorators as classes is= =A0=0A= =0A= >=A0fairly unusual. Normally, they will be regular functions.=0A= =0A= =0A= I see, this I didn't know. I'll stick to this guideline now.=0A= =0A= =0A= >=A0A more complicated case is where you need to do some pre-processing, an= d=A0=0A= > you *don't* want that calculation repeated every time the method is=0A= > called. Decorators are fantastic for that case too, but here you cannot= =0A= > access instance attributes, since the instance doesn't exist yet. But you= =0A= >=A0can access *class attributes*, as more-or-less ordinary local variables= =0A= >=A0*inside* the class definition. Here's a working sketch of the sort of= =0A= >=A0thing you can do. Copy and paste the following into a Python interactiv= e=0A= >=A0session, and then see if you can follow what is being done when.=0A= =0A= >=A0Is your mind boggled yet? :-)=0A= =0A= =0A= Steven,=0A= That was some of the coolest stuff I have seen a while. I had to wait until= I had=0A= enough time to actually run this through and utilize it my own work. I have= n't=0A= enjoyed Python this much since I first started using it.=0A= =0A= =0A= Can't thank you enough for the time and thorough example, that imparted loa= ds=0A= of insight.=0A= =0A= =0A= jlc=