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

2011-11-14 Thread Russell E. Owen
In article CALwzidk11rqXjaxcwNKy5C2iotaBO_BcDWL_zFC6Rctue=4...@mail.gmail.com, Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen ro...@uw.edu wrote: I am trying to write a decorator that times an instance method and writes the results to a class member

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, **keyArgs):

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

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 ro...@uw.edu 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()