Consider the following code:
def CalcSomething(a): if CalcSomething._cache.has_key(a): return CalcSomething._cache[a] CalcSomething._cache[a]
Turn it into a decorator.
def static_var(var_name, initial_value): def _set_var(obj): setattr(obj, var_name, initial_value) return obj return _set_var @static_var("_cache", {}) def CalcSomething(a): ...