code: def save_data(fpath, data, **kwargs):
      
      ext = splitext(fpath)[1]
      if ext in ['.pickle', '.cPkl', '.pkl']:
          return save_cPkl(fpath, data, **kwargs)
      elif ext in ['.json']:
          return save_json(fpath, data, **kwargs)
      elif ext in ['.hdf5']:
          return save_hdf5(fpath, data, **kwargs)
      elif ext in ['.txt']:
          return save_text(fpath, **kwargs)
      elif HAS_NUMPY and ext in ['.npz', '.npy']:
          return save_numpy(fpath, data, **kwargs)
      else:
          assert False, 'unknown ext=%r for fpath=%r' % (ext, fpath)
docs: More generic interface to write data