Re: Decorator question: prefer class, but only function works

2011-11-14 Thread Steven D'Aprano
On Mon, 14 Nov 2011 17:00:38 -0800, Russell E. Owen wrote: > Oops, I stripped so much out of my example that I stripped the ugly bit. > This is closer to the original and demonstrated the issue: > > def timeMethod(func): > name = func.__name__ + "Duration" > def wrapper(self, *args, **key

Re: Decorator question: prefer class, but only function works

2011-11-14 Thread Russell E. Owen
In article , Ian Kelly wrote: > On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen wrote: > > I am trying to write a decorator that times an instance method and > > writes the results to a class member variable. For example: > > > > def timeMethod(func): > >    def wrapper(self, *args, **keyArgs

Re: Decorator question: prefer class, but only function works

2011-11-10 Thread Ian Kelly
On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen wrote: > I am trying to write a decorator that times an instance method and > writes the results to a class member variable. For example: > > def timeMethod(func): >    def wrapper(self, *args, **keyArgs): >        t1 = time.time() >        res = fu

Decorator question: prefer class, but only function works

2011-11-10 Thread Russell E. Owen
I am trying to write a decorator that times an instance method and writes the results to a class member variable. For example: def timeMethod(func): def wrapper(self, *args, **keyArgs): t1 = time.time() res = func(self, *args, **keyArgs) duration = time.time() - t1