¡@

Home 

python Programming Glossary: self.cache

python resettable instance method memoization decorator

http://stackoverflow.com/questions/4431703/python-resettable-instance-method-memoization-decorator

memoized object def __init__ self func self.func func self.cache def __call__ self args kwargs key self.func args frozenset kwargs.iteritems.. key self.func args frozenset kwargs.iteritems try return self.cache key except KeyError self.cache key self.func args kwargs return.. kwargs.iteritems try return self.cache key except KeyError self.cache key self.func args kwargs return self.cache key except TypeError..

Python decorator, self is mixed up

http://stackoverflow.com/questions/5469956/python-decorator-self-is-mixed-up

decorator class cacher object def __init__ self f self.f f self.cache def __call__ self args fname self.f.__name__ if fname not in.. __call__ self args fname self.f.__name__ if fname not in self.cache self.cache fname self.f self args else print using cache return.. self args fname self.f.__name__ if fname not in self.cache self.cache fname self.f self args else print using cache return self.cache..

Python functools.wraps equivalent for classes

http://stackoverflow.com/questions/6394511/python-functools-wraps-equivalent-for-classes

def __init__ self func super .__init__ self.func func self.cache def __call__ self args try return self.cache args except KeyError.. func self.cache def __call__ self args try return self.cache args except KeyError value self.func args self.cache args value.. self.cache args except KeyError value self.func args self.cache args value return value except TypeError # uncacheable for instance..