<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save(self, segids, filepath=None, file_format='ply'):
 """ Save one or more segids into a common mesh format as a single file. segids: int, string, or list thereof filepath: string or None (optional) file_format: string (optional) Supported Formats: 'obj', 'ply' """

    if type(segids) != list:
      segids = [segids]

    meshdata = self.get(segids)

    if not filepath:
      filepath = str(segids[0]) + "." + file_format
      if len(segids) > 1:
        filepath = "{}_{}.{}".format(segids[0], segids[-1], file_format)

    if file_format == 'obj':
      objdata = mesh_to_obj(meshdata, progress=self.vol.progress)
      objdata = '\n'.join(objdata) + '\n'
      data = objdata.encode('utf8')
    elif file_format == 'ply':
      data = mesh_to_ply(meshdata)
    else:
      raise NotImplementedError('Only .obj and .ply is currently supported.')

    with open(filepath, 'wb') as f:
      f.write(data)