"Joseph L. Casale" <[email protected]> writes:
> ...
> I need to cache the results of a method on a class across all instances.
If a method call on any instance defines the return value for
all instances, then this method likely should be a class method --
and use a class attribute to store the result -- something like this:
class C(object):
_cache = {}
@classmethod
def f(cls, ...):
... determine cache key `key` ...
v = cls._cache.get(key)
if v is None:
v = cls._cache[key] = ...
return v
It will work also without the "@classmethod".
--
https://mail.python.org/mailman/listinfo/python-list