code: def write_tables_to_fits(filepath, tablelist, clobber=False,
                           namelist=None, cardslist=None, hdu_list=None):
      
      outhdulist = [fits.PrimaryHDU()]
      rmlist = []
      for i, table in enumerate(tablelist):
          ft_name = "%s._%i" % (filepath, i)
          rmlist.append(ft_name)
          try:
              os.unlink(ft_name)
          except:
              pass
          table.write(ft_name, format="fits")
          ft_in = fits.open(ft_name)
          if namelist:
              ft_in[1].name = namelist[i]
          if cardslist:
              for k, v in cardslist[i].items():
                  ft_in[1].header[k] = v
          ft_in[1].update()
          outhdulist += [ft_in[1]]
  
      if hdu_list is not None:
          for h in hdu_list:
              outhdulist.append(h)
  
      fits.HDUList(outhdulist).writeto(filepath, overwrite=clobber)
      for rm in rmlist:
          os.unlink(rm)
docs: Write some astropy.table.Table objects to a single fits file