def write(self, f_output="", f_data=""): """ writes the numpy file. :param f_output: <str> custom file output name. :param f_data: <str> data to write. :return: <bool> True for success. <bool> False for failure. """ Serializer.write(self, f_output=f_output, f_data=f_data) try: numpy.save(self.OUTPUT_PATH, self.INTERPRETED_INPUT_DATA) self.print_file_size() return True except ValueError: return False
def read(self, f_name=""): """ read the json file. :param f_name: <str> file input name. :return: <bool> True for success. <bool> False for failure. """ Serializer.read(self, f_name=f_name) with open(self.OUTPUT_PATH, 'rb') as pickle_data: try: rdata = pickle.load(pickle_data) pickle_data.close() self.READ_DATA = rdata return True except ValueError: return False
def write(self, f_output="", f_data=""): """ writes the json file. :param f_output: <str> custom file output name. :param f_data: <str> data to write. :return: <bool> True for success. <bool> False for failure. """ Serializer.write(self, f_output=f_output, f_data=f_data) with open(self.OUTPUT_PATH, 'w') as json_data: try: json.dump(self.INTERPRETED_INPUT_DATA, json_data, ensure_ascii=False, indent=4) self.print_file_size() return True except ValueError: return False
def write(self, f_output="", f_data=""): """ writes the json file. :param f_output: <str> custom file output name. :param f_data: <str> data to write. :return: <bool> True for success. <bool> False for failure. """ Serializer.write(self, f_output=f_output, f_data=f_data) with open(self.OUTPUT_PATH, 'wb') as pickle_data: try: pickle.dump(self.INTERPRETED_INPUT_DATA, pickle_data) pickle_data.close() self.print_file_size() return True except ValueError: return False
def write(self, f_output="", f_data=""): """ writes the json file. :param f_output: <str> custom file output name. :param f_data: <str> data to write. :return: <bool> True for success. <bool> False for failure. """ Serializer.write(self, f_output=f_output, f_data=f_data) success = self.serialize_data_repr(self.INTERPRETED_INPUT_DATA) if not success: raise ValueError("[Serialization Error] :: File not serialized") with open(self.OUTPUT_PATH, 'w') as uni_file: try: uni_file.writelines(self.READ_DATA) self.print_file_size() return True except ValueError: return False
def write(self, f_output="", f_data=""): """ writes the json file. :param f_output: <str> custom file output name. :param f_data: <str> data to write. :return: <bool> True for success. <bool> False for failure. """ Serializer.write(self, f_output=f_output, f_data=f_data) if DEBUG: print("[Serializer Type] :: {}".format(self.SERIALIZER_TYPE)) print("[Serializer Output] :: {}".format(self.OUTPUT_PATH)) print("[Serializer Html Output] :: {}".format( self.OUTPUT_HTML_PATH)) with open(self.OUTPUT_PATH, 'w') as yaml_data: yaml.dump(self.INTERPRETED_INPUT_DATA, yaml_data) yaml_data.close() self.print_file_size() return True
def read(self, f_name=""): """ read the yaml file. :param f_name: <str> file input name. :return: <bool> True for success. <bool> False for failure. """ success = Serializer.read(self, f_name=f_name) if not success: raise IOError("[No File] :: There is no file to read from.") with open(self.OUTPUT_PATH, 'r') as yaml_data: rdata = yaml.load(yaml_data) self.READ_DATA = rdata yaml_data.close() return True
def read(self, f_name=""): """ read the json file. :param f_name: <str> file input name. :return: <bool> True for success. <bool> False for failure. """ success = Serializer.read(self, f_name=f_name) if not success: raise IOError("[No File] :: There is no file to read from.") with open(self.OUTPUT_PATH, 'rb') as pickle_data: try: rdata = pickle.load(pickle_data) pickle_data.close() self.READ_DATA = rdata return True except ValueError: return False
def read(self, f_name=""): """ read the numpy file. :param f_name: <str> file input name. :return: <bool> True for success. <bool> False for failure. """ success = Serializer.read(self, f_name=f_name) if not success: raise IOError("[No File] :: There is no file to read from.") try: rdata = numpy.load(self.OUTPUT_PATH, encoding='bytes', allow_pickle=True) self.READ_DATA = rdata.tolist() return True except ValueError: return False
def __init__(self): # get the input data Serializer.__init__(self) self.DATA_TYPE = "dictionary"
def __init__(self): # get the input data Serializer.__init__(self) self.DATA_TYPE = "list"
def __init__(self): # get the input data Serializer.__init__(self)