fork(1) download
  1. def stubborn_cache (func):
  2. class aClass:
  3. def __init__(self):
  4. self.cache ={}
  5. def __call__(self, arg):
  6. try:
  7. value = self.cache[arg]
  8. except KeyError:
  9. value = func(arg)
  10. self.cache[arg] = value
  11. return value
  12. temp = aClass()
  13. return temp
  14.  
  15. @stubborn_cache
  16. def happy(num):
  17. print ("I'm happy")
  18. return num+1
  19.  
  20. print (happy(1))
  21. print (happy(1))
  22.  
  23.  
  24.  
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
I'm happy
2
2