How to access decorator attributes?
问题 Is it possible to access decorator attributes in Python 3? For example: is it possible to access self.misses after the call to the decorated fibonacci method? class Cache: def __init__(self, func): self.func = func self.cache = {} self.misses = 0 def __call__(self, *args): if not (args in self.cache): self.misses += 1 self.cache[args] = self.func(*args) return self.cache[args] @Cache def fibonacci(n): return n if n in (0, 1) else fibonacci(n - 1) + fibonacci(n - 2) fibonacci(20) ### now we