Anders and Briegel in Python
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

21 satır
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