Serialize model to filename.
249
def save(self, filename):
        

        with open(filename, 'wb') as savefile:
            pickle.dump(self.__dict__,
                        savefile,
                        protocol=pickle.HIGHEST_PROTOCOL)
1064169
def serialize(v, known_modules=[]):
    ''''''
    tname = name(v, known_modules=known_modules)
    func = serializer(tname)
    return func(v), tname
676946
public static void serializeObjectToFile(Object object, String filename) {
    FileOutputStream fos = null;
    ObjectOutputStream out = null;
    try {
      fos = new FileOutputStream(filename);
      out = new ObjectOutputStream(fos);
      out.writeObject(object);
      out.close();
    } catch(IOException ex) {
      ex.printStackTrace();
      System.exit(1);
    }    
  }
1023058
def _dump_model(model, attrs=None):
    

    fields = []

    for field in model._meta.fields:
        fields.append((field.name, str(getattr(model, field.name))))

    if attrs is not None:
        for attr in attrs:
            fields.append((attr, str(getattr(model, attr))))

    for field in model._meta.many_to_many:
        vals = getattr(model, field.name)
        fields.append((field.name, '{val} ({count})'.format(
            val=', '.join(map(str, vals.all())),
            count=vals.count(),
        )))

    print(', '.join(
        '{0}={1}'.format(field, value)
        for field, value in fields
    ))
668970
def serialize(self, value, primitive=False):
        """"""
        if hasattr(value, 'serialize'):
            # i.e. value is a nested model
            return value.serialize(primitive=primitive)
        else:
            return value
349384
def serialize(self, root, records):
        """"""
        logging.info("Serializing record")
        logging.debug("Root: {}".format(root))
        logging.debug("Records: {}".format(records))
        if records == {}:
            return '{}'
        if isinstance(records, dict):
            if list(records.keys())[0] == 'errors':
                logging.warning("Found errors. Moving on".format(records))
                root = None
            elif '_id' in records:
                records['id'] = records.pop('_id')
        else:
            records = list(records)

            # rename _id to id
            for r in records:
                if '_id' in r:
                    r['id'] = r.pop('_id')

        if root is not None:
            records = {root: records}
        return json.dumps(records, cls=JSONEncoder)
87099
def serialize(template, options=SerializerOptions()):
    """"""
    context = SerializerContext(options)
    context.serialize(flatten(template))
    return context.output
1212451
def serialize(self):
        """"""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = self._values.get(field_name)
            field = self.fields.get(field_name)
            if value is not None:
                if field.all:
                    value = [field.serialize(v) for v in value]
                else:
                    value = field.serialize(value)
            # Skip empty fields unless field.null
            if not field.null and ((field.all and value == []) or (not field.all and value in {None, ''})):
                continue
            data[field.name] = value
        return data
730870
def _prepare_output_multi(self, model):
        """"""
        model_name = model.__name__
        current_path = os.path.join(self._output_path, '{model}.{extension}'.format(
            model=model_name,
            extension=self.EXTENSION,
        ))
        self._outfile = codecs.open(current_path, 'w', encoding='utf-8')
        print('Dumping {model} to {file}'.format(model=model_name, file=current_path))
936406
def save_model(model, output_file):
    """"""
    if not output_file:
        return

    with open(output_file, 'wb') as f:
        pickle.dump(model, f)
    print("Saved model to file '{}'.".format(output_file))
1161423
def _to_file_format(self, iamc_index):
        """"""
        df = self.timeseries(iamc_index=iamc_index).reset_index()
        df = df.rename(columns={c: str(c).title() for c in df.columns})
        return df
1081582
def serialised( self ):
        """"""
        klass = self.__class__
        return ((klass.__module__, klass.__name__), tuple( (name, field.serialise( self._field_data[name], parent=self ) ) for name, field in klass._fields.items()))
669150
def to_file(self, filename):
        
        d = {"mass_info": self.mass_info,
             "nonbond_coeffs": self.nonbond_coeffs,
             "topo_coeffs": self.topo_coeffs}
        yaml = YAML(typ="safe")
        with open(filename, "w") as f:
            yaml.dump(d, f)
159410
def serialize(self, value, **kwargs):
        """"""
        return [self.item_type.serialize(val, **kwargs) for val in value]
60365
def render_to_file(self, filename, **kwargs):
        """"""
        with io.open(filename, 'w', encoding='utf-8') as f:
            f.write(self.render(is_unicode=True, **kwargs))
1129974
def save(self, filename):
        ''' 
        '''
        with open(filename, 'w') as outfile:
            json.dump(self.to_json(), outfile)
130887
def serialize(obj, **options):
    '''
    
    '''

    try:
        if 'file_out' in options:
            return toml.dump(obj, options['file_out'], **options)
        else:
            return toml.dumps(obj, **options)
    except Exception as error:
        raise SerializationError(error)