robert wrote:
> Bruno Desthuilliers wrote:
>> robert a écrit :
>> (snip)
>>> class MemoCache(dict): # cache expensive Objects during a session
>>> (memory only)
>>> def memo(self, k, f):
>>> try: return self[k]
>>> except KeyError: #<--------- was error
>>> return self.setdefault(k, f())
>>> cache=MemoCache()
>>> ...
>>>
>>> o = cache.memo( complex-key-expr, lambda: expensive-calc-expr )
>>>
>>
>> And how do you get back the cached value without rewriting both
>> complex-key-expr *and* expensive-calc-expr ? Or did I missed the point ?
>
> the complex-key-expr is written only once in the code
How do you get something back from the cache then ?
> expensive-calc-expr is written only once in code
Same problem here... I fail to understand how you intend to use this
"cache".
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
--
http://mail.python.org/mailman/listinfo/python-list