Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 8 година
1234567891011121314151617
  1. """
  2. Provides a decorator to cache function output to disk
  3. """
  4. import cPickle
  5. def cache_to_disk(file_name):
  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