Anders and Briegel in Python
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

21 行
514B

  1. """
  2. Useful but messy crap
  3. """
  4. def cache_to_disk(file_name):
  5. """ A decorator to cache the output of a function to disk """
  6. def wrap(func):
  7. def modified(*args, **kwargs):
  8. try:
  9. output = cPickle.load(open(file_name, "r"))
  10. except (IOError, ValueError):
  11. output = func(*args, **kwargs)
  12. with open(file_name, "w") as f:
  13. cPickle.dump(output, f)
  14. return output
  15. return modified
  16. return wrap