def save(outf, obj): """ Save a holopy object Will save objects as yaml text containing all information about the object unless outf is a filename with an image extension, in which case it will save an image, truncating metadata. Parameters ---------- outf : basestring or file Location to save the object obj : :class:`holopy.core.holopy_object.HoloPyObject` The object to save Notes ----- Marray objects are actually saved as a custom yaml file consisting of a yaml header and a numpy .npy binary array. This is done because yaml's saving of binary array is very slow for large arrays. HoloPy can read these 'yaml' files, but any other yaml implementation will get confused. """ if isinstance(outf, basestring): filename, ext = os.path.splitext(outf) if ext in ['.tif', '.TIF', '.tiff', '.TIFF']: save_image(outf, obj) return serialize.save(outf, obj)
def save(outf, obj): """ Save a holopy object Will save objects as yaml text containing all information about the object unless outf is a filename with an image extension, in which case it will save an image, truncating metadata. Parameters ---------- outf : basestring or file Location to save the object obj : :class:`holopy.core.holopy_object.HoloPyObject` The object to save Notes ----- Marray objects are actually saved as a custom yaml file consisting of a yaml header and a numpy .npy binary array. This is done because yaml's saving of binary array is very slow for large arrays. HoloPy can read these 'yaml' files, but any other yaml implementation will get confused. """ if isinstance(outf, basestring): filename, ext = os.path.splitext(outf) if ext in ['.tif', '.TIF', '.tiff', '.TIFF']: save_image(outf, obj) return serialize.save(outf, obj)
def test_json(self): """ test for serialization with json """ output = srz.save(self.data, self.output, 'json') output = unicode(output) self.output = StringIO(output) extr_data = srz.load(self.output, 'json') self.assertEqual(self.data, extr_data)
def saveFile(self): a=QMessageBox() if not serialize.save(self.filename,self.view): a.setText("Document couldn't be saved") a.exec_() else: a.setText("Document succesfully saved") a.exec_()
def start(config, file_name): """function for run project""" file_obj = open (config, "r") tp = pickle.load(file_obj); file_obj.close() file_obj = open (file_name, "r "); calendar = serialize.load(file_obj, tp) file_obj.close() calendar = Control.menu(calendar) new_tp = save_result() file_obj = open (file_name, "w"); if new_tp == "": serialize.save(calendar, file_obj, tp) else: fl = open(config, "w") pickle.dump(new_tp, fl) fl.close() serialize.save(calendar, file_obj, new_tp) file_obj.close()
def save(self): """Method which checks if filename is defined. If not, asks where to save and saves""" a=QMessageBox() if self.filename == "": path = "." fname = QFileDialog.getSaveFileName(self,"Save mindmap",path,"Mind maps (*.mindqt)") if fname.isEmpty(): return self.filename = fname if not serialize.save(self.filename,self.view): a.setText("Document couldn't be saved") a.exec_() else: a.setText("Document succesfully saved") a.exec_()
def test_pickle(self): """ test for serialization with pickle """ output = srz.save(self.data, self.output, 'pickle') self.output = BytesIO(output) extr_data = srz.load(self.output, "pickle") self.assertEqual(self.data, extr_data)
def save(self): specifier = "wb" if self.config == "pickle" else "w" with open(self.filename, specifier) as target_file: serialize.save(self._db, target_file,self.config) save_last_configs(self.config)