Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi, Sorry about the previous dup; I'm posting through Google Groups which seems to have burped. Anyways, I've "improved" things (or at least got things passing more tests). I now bind the cache to each object instance (and class for classmethods). At least one issue still remains, mostly due to

Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi Bengt, Thanks for your reply. >First, I would suggest thinking about the exact semantics of method >memoization. E.g. suppose you write > > class Oops(object): >def __init__(self, factor): self.factor = factor >@memoize_fn >def mul(self, x): >return self.f

Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi Bengt, Thanks for your reply. >First, I would suggest thinking about the exact semantics of method >memoization. E.g. suppose you write > > class Oops(object): >def __init__(self, factor): self.factor = factor >@memoize_fn >def mul(self, x): >return self.f

Memoizing decorator

2005-12-05 Thread Daishi Harada
Hi, I'm trying to find/write a memoizing decorator that works both for functions and methods. I've been looking at the following two samples: http://wiki.python.org/moin/PythonDecoratorLibrary#head-11870a08b0fa59a8622201abfac735ea47ffade5 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/32

Re: "optimizing out" getattr

2005-09-15 Thread Daishi Harada
Peter Otten wrote: > No, you can just sit back and wait -- for Python 2.5: Thanks for the tip; Although for my current use I can't target 2.5, I hadn't even noticed the attr/itemgetter additions to operator in 2.4, so I appreciate the pointer for future reference. d > $ cat attr_tuple25.py > impo

"optimizing out" getattr

2005-09-14 Thread Daishi Harada
Hi, I'd like to get the 'get2' function below to perform like the 'get1' function (I've included timeit.py results). I'm not sure how to write 'mkget' to do achieve this, however, except to use 'exec' - is that what would be necessary? Thanks in advance, d --- class A: a = 1 b = 2 a = A