Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42354

RE: Decorator help

From "Joseph L. Casale" <jcasale@activenetwerx.com>
Subject RE: Decorator help
Date 2013-03-31 00:06 +0000
References <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.4008.1364688371.2939.python-list@python.org> (permalink)

Show all headers | View raw


> When you say "class vars", do you mean variables which hold classes?


You guessed correctly, and thanks for pointing out the ambiguity in my references.


> The one doesn't follow from the other. Writing decorators as classes is 

> fairly unusual. Normally, they will be regular functions.


I see, this I didn't know. I'll stick to this guideline now.


> A more complicated case is where you need to do some pre-processing, and 
> you *don't* want that calculation repeated every time the method is
> called. Decorators are fantastic for that case too, but here you cannot
> access instance attributes, since the instance doesn't exist yet. But you
> can access *class attributes*, as more-or-less ordinary local variables
> *inside* the class definition. Here's a working sketch of the sort of
> thing you can do. Copy and paste the following into a Python interactive
> session, and then see if you can follow what is being done when.

> Is your mind boggled yet? :-)


Steven,
That was some of the coolest stuff I have seen a while. I had to wait until I had
enough time to actually run this through and utilize it my own work. I haven't
enjoyed Python this much since I first started using it.


Can't thank you enough for the time and thorough example, that imparted loads
of insight.


jlc

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Decorator help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-27 19:49 +0000
  Re: Decorator help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-27 23:29 +0000
    Re: Decorator help Jason Swails <jason.swails@gmail.com> - 2013-03-27 22:38 -0400
      Re: Decorator help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 04:58 +0000
    RE: Decorator help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-31 00:06 +0000

csiph-web