Brak opisu
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.

picklefile.py 751B

1234567891011121314151617181920212223
  1. #-*- coding: utf-8 -*-
  2. ## @brief This module handles the file storage of an editorial model
  3. import pickle
  4. from pickle import Pickler
  5. ##@brief Saves a model in a file
  6. # @param model EditorialModel : the model to save
  7. # @param filename str|None : if None return the model as pickle bytes (by default : None)
  8. # @return None if filename is a string, else returns bytes representation of model
  9. def save(model, filename = None):
  10. with open(filename, 'w+b') as ffd:
  11. pickle.dump(model, ffd)
  12. return filename
  13. ##@brief Loads a model from a file
  14. # @param filename str : the filename to use to load the model
  15. # @return EditorialModel
  16. def load(filename):
  17. with open(filename, 'rb') as ffd:
  18. edmod = pickle.load(ffd)
  19. return edmod